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

Send in x-amz-security-token header when configured (for use with IAM roles) #70

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ riofs [options] [bucketname] [mountpoint]

* Send a TERM signal to unmount filesystem and terminate running RioFS instance (example: ```killall riofs```)

* To use with IAM roles:

- acquire the credentials from http://169.254.169.254/latest/meta-data/iam/security-credentials/[ROLENAME]

- in addition to the AWS_ACCESS_KEY_ID, AWS_SECRET_KEY environment variables, also assign the token to AWS_SESSION_TOKEN

- alternatively use the session_token element in the xml configuration file

### Known limitations

* Appending data to an existing file is not supported.
Expand Down
6 changes: 6 additions & 0 deletions riofs.conf.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@
<access_key_id type="string">### AWS Access Key ID ###</access_key_id>
<secret_access_key type="string">### AWS Secret Access Key ###</secret_access_key>
-->

<!-- If using with IAM roles, use the AWS_SESSION_TOKEN environment variable or configuration file.
Uncomment the following line and replace ### strings with your data: -->
<!--
<session_token type="string">### Session Token ###</session_token>
-->
</s3>

<connection>
Expand Down
6 changes: 6 additions & 0 deletions src/http_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ gboolean http_connection_make_request (HttpConnection *con,
gpointer ctx)
{
gchar *auth_str;
gchar *session_token;
struct evhttp_request *req;
gchar auth_key[300];
time_t t;
Expand All @@ -690,6 +691,11 @@ gboolean http_connection_make_request (HttpConnection *con,
return FALSE;
}

if (conf_node_exists (application_get_conf (con->app), "s3.session_token")) {
session_token = conf_get_string (application_get_conf (con->app), "s3.session_token");
http_connection_add_output_header (con, "x-amz-security-token", session_token);
}

// if this is the first request
if (!parent_request_data) {

Expand Down
5 changes: 4 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ static void sigusr1_cb (G_GNUC_UNUSED evutil_socket_t sig, G_GNUC_UNUSED short e
LOG_err (APP_LOG, "Failed to parse configuration file: %s", _app->conf_path);
conf_destroy(conf_new);
} else {
const gchar *copy_entries[] = {"s3.host", "s3.port", "s3.versioning", "s3.access_key_id", "s3.secret_access_key", "s3.bucket_name", NULL};
const gchar *copy_entries[] = {"s3.host", "s3.port", "s3.versioning", "s3.access_key_id", "s3.secret_access_key", "s3.session_token", "s3.bucket_name", NULL};
int i;

_app->conf = conf_new;
Expand Down Expand Up @@ -850,6 +850,9 @@ int main (int argc, char *argv[])
return -1;
}
}
if (getenv("AWS_SESSION_TOKEN")) {
conf_set_string (app->conf, "s3.session_token", getenv ("AWS_SESSION_TOKEN"));
}

// check if both strings are set
if (!conf_get_string (app->conf, "s3.access_key_id") || !conf_get_string (app->conf, "s3.secret_access_key")) {
Expand Down