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

client-go: make generating certificate/key permissions more restrictive (600) #115472

Conversation

lanycrost
Copy link
Contributor

What type of PR is this?

/kind bug

What this PR does / why we need it:

GenerateSelfSignedCertKeyWithFixtures function as well as in other places keys and certificates and directories will be generated with more restrictive permissions.

Which issue(s) this PR fixes:

Fixes #110992

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

apiserver generated self-signed certificate permissions will be more restrictive


@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/bug Categorizes issue or PR as related to a bug. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Feb 2, 2023
@k8s-ci-robot
Copy link
Contributor

Welcome @lanycrost!

It looks like this is your first PR to kubernetes/kubernetes 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kubernetes has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 2, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @lanycrost. Thanks for your PR.

I'm waiting for a kubernetes 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.

@k8s-ci-robot k8s-ci-robot added needs-priority Indicates a PR lacks a `priority/foo` label and requires one. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/auth Categorizes an issue or PR as relevant to SIG Auth. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Feb 2, 2023
@cici37
Copy link
Contributor

cici37 commented Feb 2, 2023

/remove-sig api-machinery

@k8s-ci-robot k8s-ci-robot removed the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Feb 2, 2023
@k8s-ci-robot k8s-ci-robot added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Feb 3, 2023
@cici37
Copy link
Contributor

cici37 commented Feb 7, 2023

/remove-sig api-machinery

@k8s-ci-robot k8s-ci-robot removed the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Feb 7, 2023
@dims
Copy link
Member

dims commented Feb 16, 2023

/ok-to-test
/assign @liggitt

@k8s-ci-robot k8s-ci-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 Feb 16, 2023
@aojea
Copy link
Member

aojea commented Feb 16, 2023

/assign @enj
Add Mo too, he commented in the reported issue

@liggitt
Copy link
Member

liggitt commented Feb 16, 2023

looks like there's a unit test explicitly checking the old values that needs updating:

    copycerts_test.go:260: cert "ca.crt" should have mode 0644, has 0600
    copycerts_test.go:260: cert "front-proxy-ca.crt" should have mode 0644, has 0600
    copycerts_test.go:260: cert "sa.pub" should have mode 0644, has 0600
    copycerts_test.go:260: cert "etcd/ca.crt" should have mode 0644, has 0600

staging/src/k8s.io/client-go/util/cert/cert.go Outdated Show resolved Hide resolved
staging/src/k8s.io/client-go/util/cert/io.go Outdated Show resolved Hide resolved
staging/src/k8s.io/client-go/util/keyutil/key.go Outdated Show resolved Hide resolved
return nil, nil, fmt.Errorf("failed to write cert fixture to %s: %v", certFixturePath, err)
}
if err := os.WriteFile(keyFixturePath, keyBuffer.Bytes(), 0644); err != nil {
if err := os.WriteFile(keyFixturePath, keyBuffer.Bytes(), 0600); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

This is the only change in this PR I think we should consider.

That said, this code path is producing fixture files to get checked in to source control... I don't have a good sense for how a user-only readable file will behave in systems where one actor is checking out from source control and another is running the tests

Copy link
Member

Choose a reason for hiding this comment

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

Reading further, it looks like git only tracks the executable bit, and group/other permissions are solely governed by the user's umask when checking out.

That means that generating this with 0600 will likely produce fixtures with 0600 permissions, but that once they are committed and checked out, the file permissions will likely still be 0644. But since they are test fixture files being committed to source, that doesn't really matter anyway.

@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Feb 17, 2023
@lanycrost
Copy link
Contributor Author

/retest

@lanycrost
Copy link
Contributor Author

@liggitt Thanks for your valuable review. Regarding the fixture files, I understand your concern about user-only readable files and how they may behave in systems with multiple actors. It may be worthwhile to explore alternative approaches, such as generating the fixture files on the fly during testing, or having separate fixture files for each one. If I'm getting you right.

@liggitt
Copy link
Member

liggitt commented Feb 17, 2023

Generating fixtures on the fly for unit tests was expensive on underpowered CI systems and led to problems. The fixtures this leads to are things like https://github.com/kubernetes/kubernetes/tree/master/cmd/kube-apiserver/app/testing/testdata which are never used in the context of a server which can be used to create real executing workloads, only unit/integration tests which are immediately torn down and deleted.

@liggitt
Copy link
Member

liggitt commented Feb 17, 2023

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 17, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 79e28f126fd0b1d7749bfd85a831014cbc8afa54

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lanycrost, liggitt

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 17, 2023
@k8s-ci-robot k8s-ci-robot merged commit 8014155 into kubernetes:master Feb 17, 2023
@k8s-ci-robot k8s-ci-robot added this to the v1.27 milestone Feb 17, 2023
@lanycrost lanycrost deleted the client-go-110992-GenerateSelfSignedCertKeyWithFixtures-permissions branch February 20, 2023 07:25
@cici37
Copy link
Contributor

cici37 commented Feb 21, 2023

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Feb 21, 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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/auth Categorizes an issue or PR as relevant to SIG Auth. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

GenerateSelfSignedCertKeyWithFixtures private keys permissions
8 participants