Skip to content

Commit

Permalink
Merge branch 'prerel' into feat/auto-restart
Browse files Browse the repository at this point in the history
  • Loading branch information
zachmann committed Aug 27, 2024
2 parents 19115bf + 3123717 commit 6730dba
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 7 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
- `oidc-agent-service` includes the `--restart-on-update` option on default in the `oidc-agent-service.options` file,
i.e. auto-restart after update is enabled on default for agents started through `oidc-agent-service`. This can be
disabled in the `oidc-agent-service.options` file.
- Added the `--bearer` and `--auth-header` options to `oidc-token`. These can be used to ease api calls.

## Changes

- Renamed the long option of `oidc-agent` `-a` from `--bind_address` to
`--bind-address`.

### Change / Enhancement / Bugfix

Expand All @@ -43,6 +49,8 @@ This did not work as intended. We made the following changes:
- `oidc-add` can now also take an issuer url to load the default account for this issuer, i.e. `oidc-add <issuer_url>`
- `oidc-agent` now has a command line argument `--pid-file` to which the agent's pid is written.
- `oidc-agent-service` uses the new `--pid-file` option of `oidc-agent`
- If no socket path is set a default path is tried. The default path
is `$TMPDIR/oidc-agent-service-$UID/oidc-agent.sock`, this is the path used by `oidc-agent-service`

### Bugfixes

Expand Down
21 changes: 18 additions & 3 deletions src/ipc/ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@

#ifndef MINGW

char* defaultSocketPath() {
const char* tmp = getenv("TMPDIR") ?: "/tmp";
uid_t uid = getuid();
return oidc_sprintf("%s/oidc-agent-service-%d/oidc-agent.sock", tmp, uid);
}

oidc_error_t initConnectionWithoutPath(struct connection* con, int isServer,
int tcp) {
con->server = secAlloc(sizeof(struct sockaddr_un));
Expand Down Expand Up @@ -115,15 +121,24 @@ oidc_error_t ipc_client_init(struct connection* con, unsigned char remote) {
#else
const char* env_var_name =
remote ? OIDC_REMOTE_SOCK_ENV_NAME : OIDC_SOCK_ENV_NAME;
unsigned char usedDefault = 0;
#ifdef ANY_MSYS
char* path = getRegistryValue(env_var_name);
#else
char* path = oidc_strcopy(getenv(env_var_name));
if (path == NULL) {
path = defaultSocketPath();
usedDefault = 1;
}
#endif
if (path == NULL) {
char* err = oidc_sprintf("Could not get the socket path from env var '%s'. "
"Have you set the env var?\n",
env_var_name);
char* err = oidc_sprintf(
"Could not get the socket path from env var '%s'%s. "
"Have you set the env var?\nIs a agent running?\n",
env_var_name,
usedDefault
? " and could not connect to default oidc-agent-service path"
: "");
logger(WARNING, "Could not get the socket path from env var '%s'",
env_var_name);
oidc_seterror(err);
Expand Down
2 changes: 2 additions & 0 deletions src/ipc/ipc.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

#include "utils/oidc_error.h"

char* defaultSocketPath();

#ifndef MINGW
oidc_error_t initConnectionWithoutPath(struct connection*, int, int);
oidc_error_t initConnectionWithPath(struct connection*, const char*);
Expand Down
2 changes: 1 addition & 1 deletion src/oidc-agent/oidc-agent_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static struct argp_option options[] = {
"'XXXXXX' as the last six characters of a directory in the path to "
"substitute them with random characters.",
1},
{"bind_address", 'a', "PATH", OPTION_ALIAS, NULL, 1},
{"bind-address", 'a', "PATH", OPTION_ALIAS, NULL, 1},
{"always-allow-idtoken", OPT_ALWAYS_ALLOW_IDTOKEN, 0, 0,
"Always allow id-token requests without manual approval by the user.", 1},
{"json", OPT_JSON, 0, 0,
Expand Down
7 changes: 6 additions & 1 deletion src/oidc-agent/stats/statid.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,12 @@ struct statid getStatID() {
.os_info = getOSInfo(),
};
if (getAgentConfig()->stats_collect_location) {
id->location = getLocation();
char* location = getLocation();
if (strValid(location) && !strequal(location, " ")) {
id->location = location;
} else {
secFree(location);
}
}
#ifndef ANY_MSYS
secFree(b);
Expand Down
4 changes: 3 additions & 1 deletion src/oidc-gen/gen_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "defines/oidc_values.h"
#include "defines/settings.h"
#include "ipc/cryptCommunicator.h"
#include "ipc/ipc.h"
#include "oidc-agent/oidc/device_code.h"
#include "oidc-gen/device_code.h"
#include "oidc-gen/gen_consenter.h"
Expand Down Expand Up @@ -321,7 +322,8 @@ void handleCodeExchange(const struct arguments* arguments) {
#ifdef __MSYS__
socket_path = getRegistryValue(OIDC_SOCK_ENV_NAME);
#else
socket_path = oidc_strcopy(getenv(OIDC_SOCK_ENV_NAME));
socket_path =
oidc_strcopy(getenv(OIDC_SOCK_ENV_NAME)) ?: defaultSocketPath();
#endif
if (socket_path == NULL) {
printError("Socket path not encoded in url state and not available from "
Expand Down
8 changes: 7 additions & 1 deletion src/oidc-token/oidc-token.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ int main(int argc, char** argv) {
} else if ((arguments.expiration_env.useIt + arguments.token_env.useIt +
arguments.issuer_env.useIt) ==
0) { // none of these options specified
printf("%s\n", res.token);
if (arguments.bearer) {
printf("Bearer %s\n", res.token);
} else if (arguments.auth_header) {
printf("Authorization: Bearer %s", res.token);
} else {
printf("%s\n", res.token);
}
} else { // only one option specified
if (arguments.issuer_env.useIt) {
if (arguments.issuer_env.str == NULL) {
Expand Down
15 changes: 15 additions & 0 deletions src/oidc-token/oidc-token_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#define OPT_NAME 2
#define OPT_AUDIENCE 3
#define OPT_IDTOKEN 4
#define OPT_BEARER 5
#define OPT_AUTHHEADER 6

static struct argp_option options[] = {
{0, 0, 0, 0, "General:", 1},
Expand Down Expand Up @@ -48,6 +50,15 @@ static struct argp_option options[] = {
1},
{"force-new", 'f', 0, 0,
"Forces that a new access token is issued and returned.", 1},
{"bearer", OPT_BEARER, 0, 0,
"Returns the token in the bearer format that is suitable as the value"
" for an http authorization header",
1},
{"auth-header", OPT_AUTHHEADER, 0, 0,
"Returns the token included in a http authorization header for usage "
"with e.g. curl or httpie.",
1},
{"auth", OPT_AUTHHEADER, 0, OPTION_ALIAS, NULL, 1},

{0, 0, 0, 0, "Advanced:", 2},
{"scope", 's', "SCOPE", 0,
Expand Down Expand Up @@ -107,6 +118,8 @@ static error_t parse_opt(int key, char* arg, struct argp_state* state) {
case OPT_IDTOKEN: arguments->idtoken = 1; break;
case OPT_NAME: arguments->application_name = arg; break;
case OPT_AUDIENCE: arguments->audience = arg; break;
case OPT_BEARER: arguments->bearer = 1; break;
case OPT_AUTHHEADER: arguments->auth_header = 1; break;
case 'i':
arguments->issuer_env.str = arg;
arguments->issuer_env.useIt = 1;
Expand Down Expand Up @@ -174,4 +187,6 @@ void initArguments(struct arguments* arguments) {
arguments->printAll = 0;
arguments->idtoken = 0;
arguments->forceNewToken = 0;
arguments->bearer = 0;
arguments->auth_header = 0;
}
2 changes: 2 additions & 0 deletions src/oidc-token/oidc-token_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ struct arguments {
unsigned char printAll;
unsigned char idtoken;
unsigned char forceNewToken;
unsigned char bearer;
unsigned char auth_header;

time_t min_valid_period;
};
Expand Down

0 comments on commit 6730dba

Please sign in to comment.