Skip to content

Commit 1ecf404

Browse files
committed
actions/deploy: auto-renew github token instead of using single-use token
1 parent 1362e0a commit 1ecf404

File tree

3 files changed

+6
-15
lines changed

3 files changed

+6
-15
lines changed

actions/deploy/entrypoint.sh

+5-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ fi
77
if [ -n "$ACTIONS_ID_TOKEN_REQUEST_TOKEN" ]; then
88
echo "::add-mask::$ACTIONS_ID_TOKEN_REQUEST_TOKEN"
99
fi
10+
if [ -n "$ACTIONS_ID_TOKEN_REQUEST_URL" ]; then
11+
echo "::add-mask::$ACTIONS_ID_TOKEN_REQUEST_URL"
12+
fi
1013

1114
if [ -z "$OWNER" ]; then
1215
OWNER=$(echo "$GITHUB_REPOSITORY" | cut -f1 -d/)
@@ -65,12 +68,8 @@ if [ -z "$APIKEY" ]; then
6568
exit 1
6669
fi
6770

68-
payload=$(curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=hookd")
69-
jwt=$(echo "$payload" | jq -r '.value')
70-
export GITHUB_TOKEN="$jwt"
71-
72-
#export GITHUB_TOKEN_REQUEST_TOKEN="$ACTIONS_ID_TOKEN_REQUEST_TOKEN"
73-
#export GITHUB_TOKEN_REQUEST_URL="$ACTIONS_ID_TOKEN_REQUEST_URL"
71+
export GITHUB_TOKEN_URL="$ACTIONS_ID_TOKEN_REQUEST_TOKEN"
72+
export GITHUB_BEARER_TOKEN="$ACTIONS_ID_TOKEN_REQUEST_URL"
7473
else
7574
echo "::notice ::APIKEY IS DEPRECATED, PLEASE USE WORKLOAD IDENTITY, For more info see https://doc.nais.io/build/how-to/build-and-deploy and/or https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs"
7675
fi

pkg/deployclient/config.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ type Config struct {
1919
DeployServerURL string
2020
DryRun bool
2121
Environment string
22-
GitHubToken string
2322
GitHubTokenURL string
2423
GitHubBearerToken string
2524
GrpcAuthentication bool
@@ -54,7 +53,6 @@ func InitConfig(cfg *Config) {
5453
flag.StringVar(&cfg.DeployServerURL, "deploy-server", getEnv("DEPLOY_SERVER", DefaultDeployServer), "URL to API server. (env DEPLOY_SERVER)")
5554
flag.BoolVar(&cfg.DryRun, "dry-run", getEnvBool("DRY_RUN", false), "Run templating, but don't actually make any requests. (env DRY_RUN)")
5655
flag.StringVar(&cfg.Environment, "environment", os.Getenv("ENVIRONMENT"), "Environment for GitHub deployment. Autodetected from nais.yaml if not specified. (env ENVIRONMENT)")
57-
flag.StringVar(&cfg.GitHubToken, "github-token", os.Getenv("GITHUB_TOKEN"), "Deprecated. Use 'github-token-url' and 'github-bearer-token' instead. Github JWT. (env GITHUB_TOKEN)")
5856
flag.StringVar(&cfg.GitHubTokenURL, "github-token-url", os.Getenv("GITHUB_TOKEN_URL"), "URL for requesting GitHub id_token. (env GITHUB_TOKEN_URL)")
5957
flag.StringVar(&cfg.GitHubBearerToken, "github-bearer-token", os.Getenv("GITHUB_BEARER_TOKEN"), "Bearer token for use when requesting GitHub id_token. (env GITHUB_BEARER_TOKEN)")
6058
flag.BoolVar(&cfg.GrpcAuthentication, "grpc-authentication", getEnvBool("GRPC_AUTHENTICATION", true), "Use team API key to authenticate requests. (env GRPC_AUTHENTICATION)")
@@ -143,7 +141,7 @@ func (cfg *Config) Validate() error {
143141
return ErrClusterRequired
144142
}
145143

146-
githubAuth := len(cfg.GitHubToken) > 0 || (len(cfg.GitHubTokenURL) > 0 && len(cfg.GitHubBearerToken) > 0)
144+
githubAuth := len(cfg.GitHubTokenURL) > 0 && len(cfg.GitHubBearerToken) > 0
147145
if len(cfg.APIKey) == 0 && !githubAuth {
148146
return ErrAuthRequired
149147
}

pkg/deployclient/grpc.go

-6
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ func NewGrpcConnection(cfg Config) (*grpc.ClientConn, error) {
3030
TokenURL: cfg.GitHubTokenURL,
3131
Team: cfg.Team,
3232
}
33-
} else if cfg.GitHubToken != "" {
34-
interceptor = &auth_interceptor.JWTInterceptor{
35-
JWT: cfg.GitHubToken,
36-
RequireTLS: cfg.GrpcUseTLS,
37-
Team: cfg.Team,
38-
}
3933
} else {
4034
decoded, err := hex.DecodeString(cfg.APIKey)
4135
if err != nil {

0 commit comments

Comments
 (0)