Skip to content

oauth2 token exchange credentials #213

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

Merged
merged 12 commits into from
Jun 17, 2024
Prev Previous commit
Next Next commit
bump helm chart version
  • Loading branch information
kobzonega committed Jun 17, 2024
commit 66d22738fd5ccdff0b3d6e395055e71d8fcf392f
8 changes: 4 additions & 4 deletions api/v1alpha1/connection_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ type StaticCredentialsAuth struct {
}

type Oauth2TokenExchange struct {
TokenEndpoint string `json:"tokenEndpoint"`
PrivateKey *CredentialSource `json:"privateKey"`
JWTHeader *JWTHeader `json:",inline"`
JWTClaims *JWTClaims `json:",inline"`
Endpoint string `json:"endpoint"`
PrivateKey *CredentialSource `json:"privateKey"`
JWTHeader *JWTHeader `json:",inline"`
JWTClaims *JWTClaims `json:",inline"`
}

type JWTHeader struct {
Expand Down
4 changes: 2 additions & 2 deletions deploy/ydb-operator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.5.14
version: 0.5.15

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.5.14"
appVersion: "0.5.15"
6 changes: 3 additions & 3 deletions deploy/ydb-operator/crds/storage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4862,6 +4862,8 @@ spec:
properties:
audience:
type: string
endpoint:
type: string
id:
type: string
issuer:
Expand Down Expand Up @@ -4896,11 +4898,9 @@ spec:
type: string
subject:
type: string
tokenEndpoint:
type: string
required:
- endpoint
- privateKey
- tokenEndpoint
type: object
staticCredentials:
properties:
Expand Down
14 changes: 7 additions & 7 deletions internal/resources/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,7 @@ func getYDBStaticCredentials(
err)
}
}

storageEndpoint := storage.GetStorageEndpoint()
endpoint := storage.GetStorageEndpoint()

var caBundle []byte
if storage.IsStorageEndpointSecure() {
Expand All @@ -431,7 +430,7 @@ func getYDBStaticCredentials(
return ydbCredentials.NewStaticCredentials(
username,
password,
storageEndpoint,
endpoint,
ydbCredentials.WithGrpcDialOptions(dialOptions),
), nil
}
Expand All @@ -458,17 +457,18 @@ func getYDBOauth2Credentials(
privateKeyPEM, err := jwt.ParseRSAPrivateKeyFromPEM([]byte(privateKey))
if err != nil {
return nil, fmt.Errorf(
"failed to get parse RSA private key from secret: %s, key: %s, error: %w",
"failed to parse RSA private key for Oauth2TokenExchange from secret: %s, key: %s, error: %w",
auth.Oauth2TokenExhange.PrivateKey.SecretKeyRef.Name,
auth.Oauth2TokenExhange.PrivateKey.SecretKeyRef.Key,
err)
err,
)
}

var signMethod jwt.SigningMethod
if auth.Oauth2TokenExhange.JWTHeader.SignAlg != "" {
if !isSignAlgorithmSupported(auth.Oauth2TokenExhange.JWTHeader.SignAlg) {
return nil, fmt.Errorf(
"sign algorithm %s does not supported by jwt library",
"sign algorithm %s does not supported",
auth.Oauth2TokenExhange.JWTHeader.SignAlg,
)
}
Expand All @@ -478,7 +478,7 @@ func getYDBOauth2Credentials(
}

return ydbCredentials.NewOauth2TokenExchangeCredentials(
ydbCredentials.WithTokenEndpoint(auth.Oauth2TokenExhange.TokenEndpoint),
ydbCredentials.WithTokenEndpoint(auth.Oauth2TokenExhange.Endpoint),
ydbCredentials.WithAudience(auth.Oauth2TokenExhange.JWTClaims.Audience),
ydbCredentials.WithJWTSubjectToken(
ydbCredentials.WithSigningMethod(signMethod),
Expand Down