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

Audit Logging #275

Merged
merged 1 commit into from
Dec 13, 2022
Merged

Audit Logging #275

merged 1 commit into from
Dec 13, 2022

Conversation

CathalOConnorRH
Copy link
Contributor

@CathalOConnorRH CathalOConnorRH commented Dec 6, 2022

Add audit logging to grpc requests using grpc-middleware and zap logger. Addresses #246

Some example request logs are below :

grpc_cli ls
{"grpc.start_time":"2022-12-06T16:15:45Z","system":"grpc","span.kind":"server","grpc.service":"grpc.reflection.v1alpha.ServerReflection","grpc.method":"ServerReflectionInfo","peer.address":"127.0.0.1:40388","grpc.user":"unauthenticated_request","grpc.code":"OK","grpc.time_duration_in_ns":520866}

grpc_cli call
{"grpc.start_time":"2022-12-06T16:16:28Z","system":"grpc","span.kind":"server","grpc.service":"tekton.results.v1alpha2.Results","grpc.method":"ListResults","peer.address":"127.0.0.1:33534","grpc.user":"system:serviceaccount:tekton-pipelines:tekton-results-debug","grpc.issuer":"kubernetes/serviceaccount","grpc.code":"OK","grpc.time_duration_in_ns":6033652} {"grpc.start_time":"2022-12-06T16:16:28Z","system":"grpc","span.kind":"server","grpc.service":"grpc.reflection.v1alpha.ServerReflection","grpc.method":"ServerReflectionInfo","peer.address":"127.0.0.1:33534","grpc.user":"system:serviceaccount:tekton-pipelines:tekton-results-debug","grpc.issuer":"kubernetes/serviceaccount","grpc.code":"OK","grpc.time_duration_in_ns":9241731}

@tekton-robot tekton-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Dec 6, 2022
@tekton-robot
Copy link

Hi @CathalOConnorRH. Thanks for your PR.

I'm waiting for a tektoncd member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link
Contributor

@khrm khrm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/ok-to-test

@tekton-robot tekton-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Dec 6, 2022
Copy link
Contributor

@adambkaplan adambkaplan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/hold

#268 should merge first (both configure zap, thus are in conflict).

cmd/api/main.go Show resolved Hide resolved
cmd/api/main.go Show resolved Hide resolved
cmd/api/main.go Outdated

token, _, _ := new(jwt.Parser).ParseUnverified(tokenString, jwt.MapClaims{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two items:

  • Error is a potential return here. Should we raise an error, treat it as an unauthenticated request, or something else?
  • Please comment why we are using ParseUnverified. The godoc has an explict warning ("do not use unless you know what you are doing")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I will update the code to handle the error returned and log it but I think we should return the error to the calling method as it should stop the rest of the code from processing, WDYT ?
  2. We are using ParseUnverifed to just take the name of the sub from the token. we don't verify it. that's still left up to the existing code to verify. Do you think we should verify it here also ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to verify it - we indirectly verify through the TokenAccessReview. I think we just need to comment that explains "this code is just extracting values, it is not doing any form of verification".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will update the code to handle the error returned and log it but I think we should return the error to the calling method as it should stop the rest of the code from processing, WDYT ?

I do have a concern that since this is an interceptor, an error causes the request to fail. Perhaps we set grpc.user to unknown in the context?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to include those points.

@tekton-robot tekton-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 6, 2022
@CathalOConnorRH CathalOConnorRH force-pushed the add_audit_logs branch 2 times, most recently from 428ae52 to c6ecea4 Compare December 8, 2022 11:25
Copy link
Contributor

@adambkaplan adambkaplan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

Looks good to me. If there is an additional +1 or lgtm, I will lift the hold.

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 8, 2022
@alan-ghelardi
Copy link
Contributor

alan-ghelardi commented Dec 9, 2022

Eventually it'd be interesting to customize Zap settings through the config-logging ConfigMap. This would make the log output as well as the process of tweaking it homogeneous with other Tekton components, including the Watcher.

@tekton-robot
Copy link

@alan-ghelardi: changing LGTM is restricted to collaborators

In response to this:

Eventually it'd be interesting to customize Zap settings through the config-logging ConfigMap. This would make the log output as well as the process of tweaking it homogeneous with other Tekton components, including the Watcher.
/lgtm

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@dibyom
Copy link
Member

dibyom commented Dec 9, 2022

/lgtm

@tekton-robot tekton-robot added lgtm Indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Dec 9, 2022
@adambkaplan
Copy link
Contributor

/hold cancel

Once this PR is rebased, I can merge.

@tekton-robot tekton-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 12, 2022
@tekton-robot tekton-robot removed lgtm Indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Dec 13, 2022
Copy link
Contributor

@adambkaplan adambkaplan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

Re-adding LGTM due to rebase.

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 13, 2022
@tekton-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: adambkaplan

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot merged commit 5f6ad58 into tektoncd:main Dec 13, 2022
Copy link
Contributor

@khrm khrm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/kind feature
We need this label for release as discussed in the last WG call.

@tekton-robot tekton-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Feb 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants