Skip to content

Commit 64cc44b

Browse files
committed
Refactored azure OIDC and updated expiry
1 parent 50c8d29 commit 64cc44b

7 files changed

Lines changed: 26 additions & 52 deletions

File tree

.github/workflows/test.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
JFROG_CREDENTIAL_PLUGIN_BINARY_URL:
66
description: 'BINARY_URL (CI adds arch suffix automatically)'
77
required: true
8-
default: "https://partnership.jfrog.io/artifactory/credential-provider-test/jfrog-credential-provider"
8+
default: "https://releases.jfrog.io/artifactory/run/jfrog-credentials-provider/0.1.0-beta.1/jfrog-credential-provider-linux"
99
type: string
1010
DISABLE_TERRAFORM_DESTROY:
1111
description: 'DISABLE_TERRAFORM_DESTROY'
@@ -150,7 +150,11 @@ jobs:
150150
- name: Destroy Azure terraform resources
151151
id: destroy
152152
if: always() && !env.DISABLE_TERRAFORM_DESTROY
153-
continue-on-error: true
153+
uses: nick-fields/retry@v3
154+
with:
155+
timeout_minutes: 20
156+
max_attempts: 3
157+
continue-on-error: true
154158
run: |
155159
cd terraform-ci
156160
terraform destroy -input=false -auto-approve

build/terraform.tfvars.azure

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
region = "ap-northeast-3"
2-
31
# The JFrog Credential Provider binary URL (no authentication required)
42
# added by CI
53
# jfrog_credential_provider_binary_url = "https://releases.jfrog.io/artifactory/run/jfrog-credentials-provider/0.1.0-beta.1/jfrog-credential-provider-aws-linux"
@@ -12,14 +10,6 @@ artifactory_url = "partnership.jfrog.io"
1210
# The JFrog Artifactory username that will be granted the assume role permission
1311
artifactory_user = "aws-eks-user"
1412

15-
create_eks_cluster = false
16-
# cluster_public_access_cidrs = ["0.0.0.0/0"]
17-
# cluster_name = "demo-eks-cluster"
18-
19-
self_managed_eks_cluster = {
20-
name = "aws-operator-jfrog"
21-
}
22-
2313
jfrog_namespace = "jfrog"
2414

2515
enable_aws = false

internal/autoupdate/fetch.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ func fetchLatestVersionTag(ctx context.Context, client *http.Client, currentVers
7575
}
7676

7777
var latestVersionTag = addVPrefix(logs, currentVersion)
78-
if !semver.IsValid(currentVersion) {
79-
logs.Error("Current Version" + currentVersion + "isn't valid! Exiting")
80-
return "", fmt.Errorf("invalid current version: %s", currentVersion)
78+
if !semver.IsValid(latestVersionTag) {
79+
logs.Error("Current Version " + latestVersionTag + " isn't valid! Exiting")
80+
return "", fmt.Errorf("invalid current version: %s", latestVersionTag)
8181
}
8282

8383
logs.Info("Current version: " + latestVersionTag)

internal/autoupdate/validate.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import (
2525
"os"
2626
"os/exec"
2727
"strings"
28+
29+
"gopkg.in/yaml.v3"
2830
)
2931

3032
type EnvVar struct {
@@ -55,9 +57,19 @@ func loadProviderEnvsFromFile(logs *logger.Logger, configPath string, targetProv
5557
}
5658

5759
var config CredentialProviderConfig
58-
if err := json.Unmarshal(data, &config); err != nil {
59-
logs.Error("Error unmarshalling config JSON: " + err.Error())
60-
return nil, err
60+
61+
// if yaml, parse it in yaml
62+
if strings.HasSuffix(configPath, ".yaml") || strings.HasSuffix(configPath, ".yml") {
63+
if err := yaml.Unmarshal(data, &config); err != nil {
64+
logs.Error("Error unmarshalling config YAML: " + err.Error())
65+
return nil, err
66+
}
67+
} else {
68+
// if json, parse it in json
69+
if err := json.Unmarshal(data, &config); err != nil {
70+
logs.Error("Error unmarshalling config JSON: " + err.Error())
71+
return nil, err
72+
}
6173
}
6274

6375
var providerEnvs []string

internal/handlers/jfrog.go

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -86,38 +86,6 @@ func ExchangeOidcArtifactoryToken(s *service.Service, ctx context.Context,
8686
return myResponse.Username, myResponse.AccessToken, nil
8787
}
8888

89-
// ExchangeAzureOidcArtifactoryToken exchanges Azure OIDC token with JFrog Artifactory token
90-
func ExchangeAzureOidcArtifactoryToken(s *service.Service, ctx context.Context,
91-
token string, artifactoryUrl string, providerName string, clientId string) (string, string, error) {
92-
url := fmt.Sprintf("%s%s%s", "https://", artifactoryUrl, OIDC_ENDPOINT)
93-
s.Logger.Info("RT azure oidc token url :" + url)
94-
95-
requestData := OidcTokenRequest{
96-
GrantType: "urn:ietf:params:oauth:grant-type:token-exchange",
97-
ProviderName: providerName,
98-
SubjectTokenType: "urn:ietf:params:oauth:token-type:id_token",
99-
SubjectToken: token,
100-
ProviderType: "oidc-azure",
101-
Audience: clientId,
102-
}
103-
body, err := json.Marshal(requestData)
104-
if err != nil {
105-
return "", "", fmt.Errorf("error marshaling request: %v", err)
106-
}
107-
108-
resp, err := utils.HttpReq(s, ctx, url, body, nil)
109-
if err != nil {
110-
return "", "", fmt.Errorf("error calling oidc token api: %v", err)
111-
}
112-
myResponse := &OidcAccessResponse{}
113-
err = json.NewDecoder(resp.Body).Decode(myResponse)
114-
if err != nil {
115-
return "", "", fmt.Errorf("error reading artifactory response")
116-
}
117-
resp.Body.Close()
118-
return myResponse.Username, myResponse.AccessToken, nil
119-
}
120-
12189
func ExchangeAssumedRoleArtifactoryToken(s *service.Service, ctx context.Context, request *http.Request, artifactoryUrl string, secretTTL string) (string, string, error) {
12290
url := fmt.Sprintf("%s%s%s", "https://", artifactoryUrl, AWS_TOKEN_ENDPOINT)
12391
s.Logger.Info("RT token url :" + url)

internal/provider/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ func handleAzureAuth(svc *service.Service, ctx context.Context, logs *logger.Log
242242
}
243243

244244
// Exchange Azure OIDC token with JFrog Artifactory token
245-
rtUsername, rtToken, err := handlers.ExchangeAzureOidcArtifactoryToken(svc, ctx, token, artifactoryUrl, jfrogOidcProviderName, azureAppClientId)
245+
rtUsername, rtToken, err := handlers.ExchangeOidcArtifactoryToken(svc, ctx, token, artifactoryUrl, jfrogOidcProviderName, azureAppClientId)
246246
if err != nil {
247247
logs.Exit("ERROR in JFrog Credentials provider, error in createArtifactoryToken :"+err.Error(), 1)
248248
}

terraform-module/artifactory.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ resource "null_resource" "configure_artifactory_oidc" {
9898
"username": "${self.triggers.artifactory_user}",
9999
"scope": "applied-permissions/user",
100100
"audience": "*@*",
101-
"expires_in": 330
101+
"expires_in": 14400
102102
},
103103
"priority": 1
104104
}'

0 commit comments

Comments
 (0)