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

Add script to renew api-token for gitlab #46

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

heurtematte
Copy link
Contributor

@heurtematte heurtematte commented Sep 10, 2024

Renew GitLab API token for the bot user of the project <project_id> or all projects bots registered in the secretsmanager and all related tools: jenkins and otterdog (github org)

e.g:

Renew the token and update tools for the project technology.cbi:

  • gitlab_bot_token_renew.sh technology.cbi -f

Renew the token and update tools for all projects bots registered in the secretsmanager

  • gitlab_bot_token_renew.sh -f

Options:
-f: force regeneration of token
-t: keep token and force update on tools

@heurtematte heurtematte marked this pull request as draft September 10, 2024 15:49
@merks
Copy link

merks commented Sep 10, 2024

It's great to see preemptive action being take to improve token renewals in the future! ❤️ 🏆

user_id="$(_get_id_from_username "${username}")"
local name="CI token"

impersonation_tokens=$(curl -sSL --header "${TOKEN_HEADER}" \
Copy link
Contributor

Choose a reason for hiding this comment

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

Expired token may be removed from gitlab and therefore return something like:
{"error":"invalid_token","error_description":"Token is expired. You can either do re-authorization or token refresh."}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method is used as well for logging expired date of tokens.

NOTE: expired tokens are not visible from the UI, but the API returns a full list.

@heurtematte heurtematte marked this pull request as ready for review September 17, 2024 14:26
gitlab/gitlab_admin.sh Outdated Show resolved Hide resolved
@fredg02
Copy link
Contributor

fredg02 commented Sep 20, 2024

I'm a bit confused why vault is being queried for the current token, but the renewed token is only stored in pass. 🤔

@heurtematte
Copy link
Contributor Author

Vault (secretsmanager) is only used to list the paths to the existing API token key, not for reading purposes.

This is more of a preparation for the transition to the secrets manager.

@@ -263,7 +263,7 @@ check_api_token_validity() {
echo "CI Token ${username}(${user_id}) expired or revoked: $expires_at"
exit 1
else
echo "CI Token ${username}(${user_id}) is still valid, expired: $expires_at"
echo "CI Token ${username}(${user_id}) is still valid, expired on: $expires_at"
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for nitpicking, but it's a statement about the future, hence it should be: is still valid, will expire on:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

Signed-off-by: sebastien.heurtematte <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants