Skip to content

Commit 8db9b0e

Browse files
authored
Merge pull request #1288 from fluxcd/backport-1287-to-release/v1.8.x
[release/v1.8.x] Remove GCR audience reconstruction
2 parents e8dd599 + 07acb09 commit 8db9b0e

5 files changed

Lines changed: 17 additions & 28 deletions

File tree

api/v1/receiver_types.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ type ReceiverSpec struct {
8181
// to validate the payload authenticity. The Secret must contain a 'token'
8282
// key. For GCR receivers, the Secret must also contain an 'email' key
8383
// with the IAM service account email configured on the Pub/Sub push
84-
// subscription, and may optionally contain an 'audience' key with the
85-
// expected OIDC token audience.
84+
// subscription, and an 'audience' key with the expected OIDC token audience.
8685
// +required
8786
SecretRef meta.LocalObjectReference `json:"secretRef"`
8887

config/crd/bases/notification.toolkit.fluxcd.io_receivers.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ spec:
130130
to validate the payload authenticity. The Secret must contain a 'token'
131131
key. For GCR receivers, the Secret must also contain an 'email' key
132132
with the IAM service account email configured on the Pub/Sub push
133-
subscription, and may optionally contain an 'audience' key with the
134-
expected OIDC token audience.
133+
subscription, and an 'audience' key with the expected OIDC token audience.
135134
properties:
136135
name:
137136
description: Name of the referent.

docs/api/v1/notification.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ github.com/fluxcd/pkg/apis/meta.LocalObjectReference
152152
to validate the payload authenticity. The Secret must contain a ‘token’
153153
key. For GCR receivers, the Secret must also contain an ‘email’ key
154154
with the IAM service account email configured on the Pub/Sub push
155-
subscription, and may optionally contain an ‘audience’ key with the
156-
expected OIDC token audience.</p>
155+
subscription, and an &lsquo;audience&rsquo; key with the expected OIDC token audience.</p>
157156
</td>
158157
</tr>
159158
<tr>
@@ -373,8 +372,7 @@ github.com/fluxcd/pkg/apis/meta.LocalObjectReference
373372
to validate the payload authenticity. The Secret must contain a &lsquo;token&rsquo;
374373
key. For GCR receivers, the Secret must also contain an &lsquo;email&rsquo; key
375374
with the IAM service account email configured on the Pub/Sub push
376-
subscription, and may optionally contain an &lsquo;audience&rsquo; key with the
377-
expected OIDC token audience.</p>
375+
subscription, and an &lsquo;audience&rsquo; key with the expected OIDC token audience.</p>
378376
</td>
379377
</tr>
380378
<tr>

docs/spec/v1/receivers.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ The Secret referenced by `.spec.secretRef.name` must contain the following keys:
576576
|--------------|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
577577
| `token` | Yes | Random string used to salt the generated [webhook path](#webhook-path). |
578578
| `email` | Yes | The email of the IAM service account configured on the Pub/Sub push subscription for OIDC authentication. |
579-
| `audience` | No | The expected `aud` claim in the OIDC token. If omitted, the controller reconstructs it from the incoming request URL, which matches the Pub/Sub default behavior of using the push endpoint URL as the audience. Set this if you configured a custom audience on the Pub/Sub subscription. |
579+
| `audience` | Yes | The expected `aud` claim in the OIDC token. |
580580

581581
Example:
582582

@@ -591,6 +591,10 @@ type: Opaque
591591
stringData:
592592
token: <random token>
593593
email: <service-account>@<project>.iam.gserviceaccount.com
594+
# The default audience set by GCP is the full push endpoint URL, but
595+
# you can also choose a custom audience and configure it on the Pub/Sub
596+
# subscription.
597+
audience: https://<hostname>/hook/<sha256(token+name+namespace)>
594598
```
595599

596600
When the verification succeeds, the request payload is unmarshalled to the

internal/server/receiver_handlers.go

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -426,34 +426,23 @@ func (s *ReceiverServer) validate(ctx context.Context, receiver apiv1.Receiver,
426426
} `json:"message"`
427427
}
428428

429-
expectedEmail, ok := secret.Data["email"]
430-
_ = ok
429+
expectedEmail := string(secret.Data["email"])
431430
// TODO: in Flux 2.9, require the email. this will be a breaking change.
432-
// if !ok {
431+
// if expectedEmail == "" {
433432
// return fmt.Errorf("invalid secret data: required field 'email' for GCR receiver")
434433
// }
435434

436-
// Determine the expected audience. If explicitly set in the secret, use
437-
// that. Otherwise, reconstruct the webhook URL from the request, which is
438-
// the default audience used by GCR when it sends the webhook.
439-
audience := string(secret.Data["audience"])
440-
if audience == "" {
441-
scheme := "https"
442-
if r.TLS == nil {
443-
if proto := r.Header.Get("X-Forwarded-Proto"); proto != "" {
444-
scheme = proto
445-
} else {
446-
scheme = "http"
447-
}
448-
}
449-
audience = scheme + "://" + r.Host + r.URL.Path
450-
}
435+
expectedAudience := string(secret.Data["audience"])
436+
// TODO: in Flux 2.9, require the audience. this will be a breaking change.
437+
// if expectedAudience == "" {
438+
// return fmt.Errorf("invalid secret data: required field 'audience' for GCR receiver")
439+
// }
451440

452441
authenticate := authenticateGCRRequest
453442
if s.gcrTokenValidator != nil {
454443
authenticate = s.gcrTokenValidator
455444
}
456-
if err := authenticate(ctx, r.Header.Get("Authorization"), string(expectedEmail), audience); err != nil {
445+
if err := authenticate(ctx, r.Header.Get("Authorization"), expectedEmail, expectedAudience); err != nil {
457446
return fmt.Errorf("cannot authenticate GCR request: %w", err)
458447
}
459448

0 commit comments

Comments
 (0)