Skip to content

Commit b371389

Browse files
authored
Merge pull request #2154 from vmware-tanzu/jtc/fixup-before-audit-release
Small fixups prior to releasing audit log story
2 parents 8322b03 + 87640ca commit b371389

File tree

3 files changed

+60
-52
lines changed

3 files changed

+60
-52
lines changed

hack/lib/kind-config/single-node.yaml

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
#@ load("@ytt:data", "data")
2-
2+
---
33
kind: Cluster
44
apiVersion: kind.x-k8s.io/v1alpha4
55
nodes:
6-
- role: control-plane
7-
extraPortMappings:
8-
- protocol: TCP
9-
#! This same port number is hardcoded in the integration test setup
10-
#! when creating a Service on a kind cluster. It is used to talk to
11-
#! the supervisor app via HTTPS.
12-
containerPort: 31243
13-
hostPort: 12344
14-
listenAddress: 127.0.0.1
15-
- protocol: TCP
16-
#! This same port number is hardcoded in the integration test setup
17-
#! when creating a Service on a kind cluster. It is used to talk to
18-
#! the Dex app.
19-
containerPort: 31235
20-
hostPort: 12346
21-
listenAddress: 127.0.0.1
22-
#@ if data.values.enable_audit_logs:
23-
#! mount the local file on the control plane
24-
extraMounts:
25-
- hostPath: /tmp/metadata-audit-policy.yaml
26-
containerPath: /etc/kubernetes/policies/audit-policy.yaml
27-
readOnly: true
28-
#@ end
6+
- role: control-plane
7+
extraPortMappings:
8+
- protocol: TCP
9+
#! This same port number is hardcoded in the integration test setup
10+
#! when creating a Service on a kind cluster. It is used to talk to
11+
#! the supervisor app via HTTPS.
12+
containerPort: 31243
13+
hostPort: 12344
14+
listenAddress: 127.0.0.1
15+
- protocol: TCP
16+
#! This same port number is hardcoded in the integration test setup
17+
#! when creating a Service on a kind cluster. It is used to talk to
18+
#! the Dex app.
19+
containerPort: 31235
20+
hostPort: 12346
21+
listenAddress: 127.0.0.1
22+
#@ if data.values.enable_audit_logs:
23+
#! mount the local file on the control plane
24+
extraMounts:
25+
- hostPath: /tmp/metadata-audit-policy.yaml
26+
containerPath: /etc/kubernetes/policies/audit-policy.yaml
27+
readOnly: true
28+
#@ end
2929
#! Apply these patches to all nodes.
3030
kubeadmConfigPatches:
3131
- |
@@ -45,20 +45,20 @@ kubeadmConfigPatches:
4545
- |
4646
kind: ClusterConfiguration
4747
apiServer:
48-
#! enable auditing flags on the API server
49-
extraArgs:
50-
audit-log-path: /var/log/kubernetes/kube-apiserver-audit.log
51-
audit-policy-file: /etc/kubernetes/policies/audit-policy.yaml
52-
#! mount new files / directories on the control plane
53-
extraVolumes:
54-
- name: audit-policies
55-
hostPath: /etc/kubernetes/policies
56-
mountPath: /etc/kubernetes/policies
57-
readOnly: true
58-
pathType: "DirectoryOrCreate"
59-
- name: "audit-logs"
60-
hostPath: "/var/log/kubernetes"
61-
mountPath: "/var/log/kubernetes"
62-
readOnly: false
63-
pathType: DirectoryOrCreate
48+
#! enable auditing flags on the API server
49+
extraArgs:
50+
audit-log-path: /var/log/kubernetes/kube-apiserver-audit.log
51+
audit-policy-file: /etc/kubernetes/policies/audit-policy.yaml
52+
#! mount new files / directories on the control plane
53+
extraVolumes:
54+
- name: audit-policies
55+
hostPath: /etc/kubernetes/policies
56+
mountPath: /etc/kubernetes/policies
57+
readOnly: true
58+
pathType: "DirectoryOrCreate"
59+
- name: "audit-logs"
60+
hostPath: "/var/log/kubernetes"
61+
mountPath: "/var/log/kubernetes"
62+
readOnly: false
63+
pathType: DirectoryOrCreate
6464
#@ end

internal/federationdomain/endpoints/callback/callback_handler.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"go.pinniped.dev/internal/federationdomain/federationdomainproviders"
1919
"go.pinniped.dev/internal/federationdomain/formposthtml"
2020
"go.pinniped.dev/internal/federationdomain/oidc"
21-
"go.pinniped.dev/internal/federationdomain/stateparam"
2221
"go.pinniped.dev/internal/httputil/httperr"
2322
"go.pinniped.dev/internal/httputil/securityheader"
2423
"go.pinniped.dev/internal/plog"
@@ -46,16 +45,11 @@ func NewHandler(
4645
return httperr.New(http.StatusBadRequest, "error parsing request params")
4746
}
4847

49-
encodedState, decodedState, err := validateRequest(r, stateDecoder, cookieDecoder)
48+
decodedState, err := validateRequest(r, stateDecoder, cookieDecoder, auditLogger)
5049
if err != nil {
5150
return err
5251
}
5352

54-
auditLogger.Audit(auditevent.AuthorizeIDFromParameters, &plog.AuditParams{
55-
ReqCtx: r.Context(),
56-
KeysAndValues: []any{"authorizeID", encodedState.AuthorizeID()},
57-
})
58-
5953
idp, err := upstreamIDPs.FindUpstreamIDPByDisplayName(decodedState.UpstreamName)
6054
if err != nil || idp == nil {
6155
plog.Warning("upstream provider not found")
@@ -141,23 +135,28 @@ func authcode(r *http.Request) string {
141135
return r.FormValue("code")
142136
}
143137

144-
func validateRequest(r *http.Request, stateDecoder, cookieDecoder oidc.Decoder) (stateparam.Encoded, *oidc.UpstreamStateParamData, error) {
138+
func validateRequest(r *http.Request, stateDecoder, cookieDecoder oidc.Decoder, auditLogger plog.AuditLogger) (*oidc.UpstreamStateParamData, error) {
145139
if r.Method != http.MethodGet {
146-
return "", nil, httperr.Newf(http.StatusMethodNotAllowed, "%s (try GET)", r.Method)
140+
return nil, httperr.Newf(http.StatusMethodNotAllowed, "%s (try GET)", r.Method)
147141
}
148142

149143
encodedState, decodedState, err := oidc.ReadStateParamAndValidateCSRFCookie(r, cookieDecoder, stateDecoder)
150144
if err != nil {
151145
plog.InfoErr("state or CSRF error", err)
152-
return "", nil, err
146+
return nil, err
153147
}
154148

149+
auditLogger.Audit(auditevent.AuthorizeIDFromParameters, &plog.AuditParams{
150+
ReqCtx: r.Context(),
151+
KeysAndValues: []any{"authorizeID", encodedState.AuthorizeID()},
152+
})
153+
155154
if authcode(r) == "" {
156155
plog.Info("code param not found")
157-
return "", nil, httperr.New(http.StatusBadRequest, errorMsgForNoCodeParam(r))
156+
return nil, httperr.New(http.StatusBadRequest, errorMsgForNoCodeParam(r))
158157
}
159158

160-
return encodedState, decodedState, nil
159+
return decodedState, nil
161160
}
162161

163162
func errorMsgForNoCodeParam(r *http.Request) string {

internal/federationdomain/endpoints/callback/callback_handler_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,9 @@ func TestCallbackEndpoint(t *testing.T) {
12061206
"error_uri": "some uri",
12071207
},
12081208
}),
1209+
testutil.WantAuditLog("AuthorizeID From Parameters", map[string]any{
1210+
"authorizeID": encodedStateParam.AuthorizeID(),
1211+
}),
12091212
}
12101213
},
12111214
},
@@ -1233,6 +1236,9 @@ func TestCallbackEndpoint(t *testing.T) {
12331236
"error_description": "some description",
12341237
},
12351238
}),
1239+
testutil.WantAuditLog("AuthorizeID From Parameters", map[string]any{
1240+
"authorizeID": encodedStateParam.AuthorizeID(),
1241+
}),
12361242
}
12371243
},
12381244
},
@@ -1255,6 +1261,9 @@ func TestCallbackEndpoint(t *testing.T) {
12551261
testutil.WantAuditLog("HTTP Request Parameters", map[string]any{
12561262
"params": map[string]any{"state": "redacted"},
12571263
}),
1264+
testutil.WantAuditLog("AuthorizeID From Parameters", map[string]any{
1265+
"authorizeID": encodedStateParam.AuthorizeID(),
1266+
}),
12581267
}
12591268
},
12601269
},

0 commit comments

Comments
 (0)