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

Set HOME_MODE to 0700 in Flatcar images #1400

Merged
merged 2 commits into from
Feb 21, 2024

Conversation

weseven
Copy link
Contributor

@weseven weseven commented Feb 8, 2024

What this PR does / why we need it:

This sets HOME_MODE to 0700 in /etc/login.defs.

Currently it is unset in Flatcar (coming from Gentoo that keeps the upstream setting).
When HOME_MODE is unset, useradd uses the default umask of 022 when creating home directories for users.
This causes home directories for all users created through ignition in Flatcar to be world readable.

Setting HOME_MODE to 0700 restrict home permissions to the owner, as is default in RHEL derived distros (Ubuntu uses 0750).

Signed-off-by: Daniel Simionato <daniel.simionato@gmail.com>
Copy link

linux-foundation-easycla bot commented Feb 8, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: weseven / name: Daniel Simionato (317138e, c1dad35)
  • ✅ login: jepio / name: Jeremi Piotrowski (c1dad35)

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Feb 8, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @weseven!

It looks like this is your first PR to kubernetes-sigs/image-builder 🎉. 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-sigs/image-builder 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 the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Feb 8, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @weseven. Thanks for your PR.

I'm waiting for a kubernetes-sigs 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 size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Feb 8, 2024
@AverageMarcus
Copy link
Member

/ok-to-test

@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 9, 2024
Copy link
Contributor

@mboersma mboersma left a comment

Choose a reason for hiding this comment

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

Makes sense to me. Let's see if some Flatcar experts can also check this.

/cc @jepio @invidian

@k8s-ci-robot
Copy link
Contributor

@mboersma: GitHub didn't allow me to request PR reviews from the following users: jepio.

Note that only kubernetes-sigs members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

Makes sense to me. Let's see if some Flatcar experts can also check this.

/cc @jepio @invidian

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.

@invidian
Copy link
Member

invidian commented Feb 9, 2024

Makes sense to me. Let's see if some Flatcar experts can also check this.

I wonder if this is something Flatcar upstream would be interested or what can be done using Ignition, since that would be probably more desirable than per-project hardening like in this case.

@weseven
Copy link
Contributor Author

weseven commented Feb 9, 2024

I can give more context on that, since I made two PRs upstream:

In flatcar the file can be changed through ignition, true, but from my tests users created through the same ignition file will still have world readable home directories (that is, the useradd calls during ignition do not use the overridden value).

I do believe setting HOME_MODE to 0700 is a safer default, and in fact world readable home directories are a basic check in security assessments. Keeping it unset will have a vanilla flatcar image fail the basic checks (e.g., CIS Benchmarks).

This might also be useful to apply to other distros: RedHat based distributions already set it to 0700, Ubuntu sets it to 0750, but Debian for example leaves it commented as the upstream package.

@invidian
Copy link
Member

invidian commented Feb 9, 2024

If this cannot be done via Ignition, I guess the change is fine, although it might be breaking for users which rely on that read access (I hit similar issue with Mariner recently). I always have a feeling that upstream image-builder should provide minimal viable images while hardening should be done for specific use-cases, similar to all other customizations, but I might be wrong, so I will let others decide :)

@drew-viles
Copy link
Contributor

My two cents (from someone, who in reality, knows zero about Flatcar).

I'd be happy for this to go in because as a general rule because it hardens security and I would like to see a more security focused image coming out of the builder. Whilst we shouldn't be dictating the security posture of everyone, we should be providing as secure an image as is feasibly possible without hindering peoples development and deployments.

That being said, I'd also like to see how it goes forward in the Flatcar repo because if it's fixed upstream, it seems a bit redundant to then have it set within image-builder too.

@jepio
Copy link
Contributor

jepio commented Feb 12, 2024

In flatcar the file can be changed through ignition, true, but from my tests users created through the same ignition file will still have world readable home directories (that is, the useradd calls during ignition do not use the overridden value).

FWIW: the way to do it through ignition would be like this:

variant: flatcar
version: 1.0.0
storage:
  directories:
  - path: /home/jeremi
    mode: 0700
passwd:
  users:
  - name: jeremi

(I couldn't get it to work for the default core user though).

That being said, I'd also like to see how it goes forward in the Flatcar repo because if it's fixed upstream, it seems a bit redundant to then have it set within image-builder too.

I'd say it's probably a good idea - it's a better default and will be available faster if the change is done in image-builder.

Co-authored-by: Jeremi Piotrowski <jeremi.piotrowski@gmail.com>
Copy link
Contributor

@mboersma mboersma left a comment

Choose a reason for hiding this comment

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

/lgtm

Seems like we have a rough consensus that making this change here is worthwhile, although ideally it could be done upstream or in ignition.

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

@mboersma mboersma left a comment

Choose a reason for hiding this comment

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

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mboersma

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 21, 2024
@k8s-ci-robot k8s-ci-robot merged commit 5a3bcbd into kubernetes-sigs:main Feb 21, 2024
9 checks passed
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. lgtm "Looks good to me", 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/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants