Skip to content

Commit 50752be

Browse files
committed
Revert "actions/deploy: auto-renew github token instead of using single-use token"
This reverts commit 1ecf404.
1 parent 1ecf404 commit 50752be

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

actions/deploy/entrypoint.sh

+6-5
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ 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
1310

1411
if [ -z "$OWNER" ]; then
1512
OWNER=$(echo "$GITHUB_REPOSITORY" | cut -f1 -d/)
@@ -68,8 +65,12 @@ if [ -z "$APIKEY" ]; then
6865
exit 1
6966
fi
7067

71-
export GITHUB_TOKEN_URL="$ACTIONS_ID_TOKEN_REQUEST_TOKEN"
72-
export GITHUB_BEARER_TOKEN="$ACTIONS_ID_TOKEN_REQUEST_URL"
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"
7374
else
7475
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"
7576
fi

pkg/deployclient/config.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type Config struct {
1919
DeployServerURL string
2020
DryRun bool
2121
Environment string
22+
GitHubToken string
2223
GitHubTokenURL string
2324
GitHubBearerToken string
2425
GrpcAuthentication bool
@@ -53,6 +54,7 @@ func InitConfig(cfg *Config) {
5354
flag.StringVar(&cfg.DeployServerURL, "deploy-server", getEnv("DEPLOY_SERVER", DefaultDeployServer), "URL to API server. (env DEPLOY_SERVER)")
5455
flag.BoolVar(&cfg.DryRun, "dry-run", getEnvBool("DRY_RUN", false), "Run templating, but don't actually make any requests. (env DRY_RUN)")
5556
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)")
5658
flag.StringVar(&cfg.GitHubTokenURL, "github-token-url", os.Getenv("GITHUB_TOKEN_URL"), "URL for requesting GitHub id_token. (env GITHUB_TOKEN_URL)")
5759
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)")
5860
flag.BoolVar(&cfg.GrpcAuthentication, "grpc-authentication", getEnvBool("GRPC_AUTHENTICATION", true), "Use team API key to authenticate requests. (env GRPC_AUTHENTICATION)")
@@ -141,7 +143,7 @@ func (cfg *Config) Validate() error {
141143
return ErrClusterRequired
142144
}
143145

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

pkg/deployclient/grpc.go

+6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ 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+
}
3339
} else {
3440
decoded, err := hex.DecodeString(cfg.APIKey)
3541
if err != nil {

0 commit comments

Comments
 (0)