Skip to content
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

feat(auth): adds support for X509 workload identity federation #10373

Merged
merged 18 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: added more comments
  • Loading branch information
aeitzman committed Jun 27, 2024
commit ec03913f4ba06e940e4d5acaf13376019d35660e
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ func (o *Options) client() (*http.Client, error) {
return o.Client, nil
}

// If the client was a default client, and a certificate source is present, validate and
// use that certificate source to create a new mTLS client.
cert := o.CredentialSource.Certificate
if !cert.UseDefaultCertificateConfig && cert.CertificateConfigLocation == "" {
return nil, errors.New("credentials: \"certificate\" object must either specify a certificate_config_location or use_default_certificate_config should be true")
Expand Down
10 changes: 9 additions & 1 deletion auth/credentials/internal/externalaccount/x509_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ import (
"cloud.google.com/go/auth/internal/transport/cert"
)

// x509Provider implements the subjectTokenProvider type for
// x509 workload identity credentials. Because x509 credentials
// rely on an mTLS connection to represent the 3rd party identity
// rather than a subject token, this provider will always return
// an empty string when a subject token is requested by the external account
// token provider.
type x509Provider struct {
}

Expand All @@ -34,6 +40,8 @@ func (xp *x509Provider) subjectToken(ctx context.Context) (string, error) {
return "", nil
codyoss marked this conversation as resolved.
Show resolved Hide resolved
}

// createX509Client creates a new client that is configured with mTLS, using the
// certificate configuration specified in the credential source.
func createX509Client(certificateConfigLocation string) (*http.Client, error) {
certProvider, err := cert.NewWorkloadX509CertProvider(certificateConfigLocation)
if err != nil {
Expand All @@ -45,7 +53,7 @@ func createX509Client(certificateConfigLocation string) (*http.Client, error) {
GetClientCertificate: certProvider,
}

// Create client with default settings plus the X509 workload certs
// Create a client with default settings plus the X509 workload cert and key.
client := &http.Client{
Transport: trans,
Timeout: 30 * time.Second,
Expand Down
Loading