Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions internal/oidc/oidc_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,15 @@ func CreateOIDCCredential(cred config.Credential, client *http.Client) (*OIDCCre
clientID := cred.GetString("client-id")

// jfrog values
feedUrl := cred.GetString("url")
jfrogOidcProviderName := cred.GetString("jfrog-oidc-provider-name")
feedUrl := getFirstString(cred, "url", "registry")
jfrogOidcProviderName := getFirstString(cred, "jfrog-oidc-provider-name", "oidc-provider-name")
jfrogAudience := getFirstString(cred, "audience", "oidc-audience")
jfrogIdentityMappingName := getFirstString(
cred,
"identity-mapping-name",
"oidc-identity-mapping-name",
"jfrog-oidc-identity-mapping-name",
)

// aws values
awsRegion := cred.GetString("aws-region")
Expand Down Expand Up @@ -133,8 +140,8 @@ func CreateOIDCCredential(cred config.Credential, client *http.Client) (*OIDCCre
JFrogURL: fmt.Sprintf("%s://%s", jfrogUrlParsed.Scheme, jfrogUrlParsed.Host),
ProviderName: jfrogOidcProviderName,
// optional
Audience: cred.GetString("audience"),
IdentityMappingName: cred.GetString("identity-mapping-name"),
Audience: jfrogAudience,
IdentityMappingName: jfrogIdentityMappingName,
}
case awsRegion != "" && accountID != "" && roleName != "" && domain != "" && domainOwner != "":
audience := cred.GetString("audience")
Expand Down Expand Up @@ -182,6 +189,16 @@ func CreateOIDCCredential(cred config.Credential, client *http.Client) (*OIDCCre
}, nil
}

func getFirstString(cred config.Credential, keys ...string) string {
for _, key := range keys {
if value := cred.GetString(key); value != "" {
return value
}
}

return ""
}

// GetOrRefreshOIDCToken gets a cached token or fetches a new one if expired
func GetOrRefreshOIDCToken(cred *OIDCCredential, ctx context.Context) (string, error) {
if cred.isRejected {
Expand Down
15 changes: 15 additions & 0 deletions internal/oidc/oidc_credential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,21 @@ func TestTryCreateOIDCCredential(t *testing.T) {
IdentityMappingName: "test-mapping",
},
},
{
"jfrog with org-level aliases",
config.Credential{
"registry": "https://jfrog.example.com/artifactory/api/npm/my-feed",
"oidc-provider-name": "some-provider",
"oidc-audience": "test-audience",
"jfrog-oidc-identity-mapping-name": "test-mapping",
},
&JFrogOIDCParameters{
JFrogURL: "https://jfrog.example.com",
ProviderName: "some-provider",
Audience: "test-audience",
IdentityMappingName: "test-mapping",
},
},
{
"looks like jfrog but missing provider-name",
config.Credential{
Expand Down
Loading