Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update S3 cache to read AWS_SESSION_TOKEN env var if present #339

Merged
merged 3 commits into from
May 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions lib/cache_rest.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ struct mapcache_cache_s3 {
mapcache_cache_rest cache;
char *id;
char *secret;
char *session_token;
char *region;
char *credentials_file;
};
Expand Down Expand Up @@ -868,16 +869,18 @@ static void _mapcache_cache_s3_headers_add(mapcache_context *ctx, const char* me
if((rv=apr_file_open(&f, s3->credentials_file,
APR_FOPEN_READ|APR_FOPEN_BUFFERED|APR_FOPEN_BINARY,APR_OS_DEFAULT,
ctx->pool)) == APR_SUCCESS) {
char line[2048];
if( (rv = apr_file_gets(line,2048,f))== APR_SUCCESS) {
// Line length buffer increased to handle longer session tokens; see:
// https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_request.html
char line[4096];
if( (rv = apr_file_gets(line,4096,f))== APR_SUCCESS) {
_remove_lineends(line);
aws_access_key_id = apr_pstrdup(ctx->pool,line);
}
if( (rv = apr_file_gets(line,2048,f))== APR_SUCCESS) {
if( (rv = apr_file_gets(line,4096,f))== APR_SUCCESS) {
_remove_lineends(line);
aws_secret_access_key = apr_pstrdup(ctx->pool,line);
}
if( (rv = apr_file_gets(line,2048,f))== APR_SUCCESS) {
if( (rv = apr_file_gets(line,4096,f))== APR_SUCCESS) {
_remove_lineends(line);
aws_security_token = apr_pstrdup(ctx->pool,line);
}
Expand All @@ -894,7 +897,7 @@ static void _mapcache_cache_s3_headers_add(mapcache_context *ctx, const char* me
} else {
aws_access_key_id = s3->id;
aws_secret_access_key = s3->secret;
aws_security_token = NULL;
aws_security_token = s3->session_token;
}

if(!strcmp(method,"PUT")) {
Expand Down Expand Up @@ -1366,6 +1369,13 @@ static void _mapcache_cache_s3_configuration_parse_xml(mapcache_context *ctx, ez
ctx->set_error(ctx,400,"s3 cache (%s) is missing required <secret> child or AWS_SECRET_ACCESS_KEY environment", cache->name);
return;
}
if ((cur_node = ezxml_child(node,"session_token")) != NULL) {
s3->session_token = apr_pstrdup(ctx->pool, cur_node->txt);
} else if ( getenv("AWS_SESSION_TOKEN")) {
s3->session_token = apr_pstrdup(ctx->pool,getenv("AWS_SESSION_TOKEN"));
} else {
s3->session_token = NULL;
}
}
if ((cur_node = ezxml_child(node,"region")) != NULL) {
s3->region = apr_pstrdup(ctx->pool, cur_node->txt);
Expand Down
Loading