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

Implement automatic regeneration of AWS ECR tokens #2982

Closed
wants to merge 1 commit into from

Conversation

supra08
Copy link
Contributor

@supra08 supra08 commented Jan 20, 2021

This PR contains a mechanism for regeneration of AWS ECR tokens to evade their expiry after 12 hours.
Earlier this was a manual task, that required manual deletion of secret, fetching the new token and again creating a secret. For this process, a Kubernetes cron job resource has been added. It runs a script containing the above instructions after 6 hours.

For configuring the aws-cli within the pod, the given aws iam user credentials are used from the terraform resources.

Suggestions are welcome for this implementation.

Fixes #1900

Base automatically changed from master to main February 23, 2021 18:09
@fullmetalrooster fullmetalrooster self-assigned this Feb 26, 2021
@@ -106,3 +106,57 @@ data "template_file" "gitpod_registry_values" {
secret_name = local.secret_name
}
}

esource "aws_iam_user" "gitpod_registry" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in esource

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are creating the IAM user here but you are not giving it any permissions so naturally it will not be able to refresh the token. what you want is the same permissions from resource "aws_iam_role_policy" "dns_manager" { or the very least "ecr:GetAuthorizationToken"

}

data "template_file" "ecr_regeneration_script" {
template = file("${path.module}/template/regenerate-ecr.tpl")
Copy link
Contributor

@komapa komapa Mar 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
template = file("${path.module}/template/regenerate-ecr.tpl")
template = file("${path.module}/templates/regenerate-ecr.tpl")


resource "kubernetes_cron_job" "ecr_regeneration_cron" {
metadata {
name = "ecr_regeneration_cron"
Copy link
Contributor

@komapa komapa Mar 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name = "ecr_regeneration_cron"
name = "ecr-regeneration-cron"

Error: metadata.0.name a DNS-1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is 'a-z0-9?(.a-z0-9?)*')

@komapa
Copy link
Contributor

komapa commented Mar 10, 2021

Tested this this on a somewhat vanilla AWS self-hosted installation (version 0.8.0-beta1):

You must specify a region. You can also configure your region by running "aws configure".
Error from server (Forbidden): secrets "gitpod-registry" is forbidden: User "system:serviceaccount:default:default" cannot delete resource "secrets" in API group "" in the namespace "default"
Error from server (Forbidden): secrets is forbidden: User "system:serviceaccount:default:default" cannot create resource "secrets" in API group "" in the namespace "default"
Error from server (Forbidden): serviceaccounts "default" is forbidden: User "system:serviceaccount:default:default" cannot get resource "serviceaccounts" in API group "" in the namespace "default"
Token regeneration complete

# Set the AWS auth environment variables
AWS_DEFAULT_REGION=${region}
AWS_SECRET_ACCESS_KEY=${secret_key}
AWS_ACCESS_KEY_ID=${access_key}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These needs some export in order to be available in the TOKEN subshell below. With that said though, I believe it is much better if those ENV are set on the cronjob at runtime and are proper Kubernetes secrets instead. Embedding them like this in the command makes them readable to most people with access to Kubernetes as you would like to allow people to see cronjobs but NOT secrets.

@dimazaur
Copy link

Please check this PR #3977
With fixes for AWS ECR token registration

@stale
Copy link

stale bot commented Jul 15, 2021

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the meta: stale This issue/PR is stale and will be closed soon label Jul 15, 2021
@stale stale bot closed this Jul 25, 2021
@AlexTugarev AlexTugarev deleted the supra08/authorization-token-expired-1900 branch March 15, 2022 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meta: stale This issue/PR is stale and will be closed soon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Authorization token expired
4 participants