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

Dracut: Update Dracut overlay module to correctly locate 'chcon' #11986

Merged
merged 1 commit into from
Mar 10, 2025

Conversation

gmileka
Copy link
Contributor

@gmileka gmileka commented Jan 17, 2025

Merge Checklist

All boxes should be checked before merging the PR (just tick any boxes which don't apply to this PR)

  • [n/a] The toolchain has been rebuilt successfully (or no changes were made to it)
  • [n/a] The toolchain/worker package manifests are up-to-date
  • [ok] Any updated packages successfully build (or no packages were changed)
  • [n/a] Packages depending on static components modified in this PR (Golang, *-static subpackages, etc.) have had their Release tag incremented.
  • [ok] Package tests (%check section) have been verified with RUN_CHECK=y for existing SPEC files, or added to new SPEC files
  • [ok] All package sources are available
  • [ok] cgmanifest files are up-to-date and sorted (./cgmanifest.json, ./toolkit/scripts/toolchain/cgmanifest.json, .github/workflows/cgmanifest.json)
  • [ok] LICENSE-MAP files are up-to-date (./LICENSES-AND-NOTICES/SPECS/data/licenses.json, ./LICENSES-AND-NOTICES/SPECS/LICENSES-MAP.md, ./LICENSES-AND-NOTICES/SPECS/LICENSE-EXCEPTIONS.PHOTON)
  • [ok] All source files have up-to-date hashes in the *.signatures.json files
  • [ok] sudo make go-tidy-all and sudo make go-test-coverage pass
  • [n/a] Documentation has been updated to match any changes to the build system
  • [ok] Ready to merge

Summary

LiveOS ISO utilizes an overlay file system that consists of a read-only full OS rootfs (lower dir) and an in-memory read-write file system (upper dir).

When selinux is enabled, the final root (/) must be labeled root_t. Given that the final root (/) is constructed from the lower dir and the upper dir, both should also be marked as such (i.e. with root_t). The read-only full OS rootfs is already labeled as such during build time. The in-memory file system is new, however, and still need to be labeled.

A fix was merged in December to achieve that by calling selinux chcon utility. At the time, the labeling was done correctly, and selinux did not report any violations in our private testing.

However, this bug report alerted us that chcon is not being found on the path as tested by Brian, and as a result, the labeling is not taking place, and the liveos iso does not boot when selinux is enabled.

This fix changes the dracut module responsible for the labeling to explicitly specify the full path of the chcon utility. This guarantees that regardless of the contents of the initrd, the command always succeeds.

When doing root cause analysis for the regression, the most likely reason it did not not show in the private testing is that the initrd had a copy of chcon, and it was on the path. This hid the problem that would arise if the contents of the initrd changed.

Change Log
Does this affect the toolchain?
  • NO
Associated issues
  • n/a
Links to CVEs
  • n/a
Test Methodology

Validation

  • Locally, on dev box:
    • New enlistment of Azure Linux.
    • Build the dracut package.
    • Build the baremela image.
    • Build Prism.
    • Use Prism to build a LiveOS ISO.
    • Create a VM with the generated ISO.
    • Boot the VM.
    • Log-in.
    • Verify that no selinux denials exist in the journal logs.

Automation

  • Enabled the VM tests suite in the Prism build/test pipelines.
    • Download varius Azure Linux 2.0/3.0 images.
    • Customize using Prism.
    • Ensure they all boot, get an IP, and the test can ssh and inspect the contents.

Note While we've put in automation to catch this kind of failures in the future, the downloaded images in the test are the public one which do not have the fixed Dracut package. However, once the Dracut package is published, the test will automatically pick it up and verify it boots.

@microsoft-github-policy-service microsoft-github-policy-service bot added Packaging 3.0-dev PRs Destined for AzureLinux 3.0 labels Jan 17, 2025
Comment on lines 152 to 153
+allow ssh_keygen_t var_t:dir { write add_name remove_name };
+allow ssh_keygen_t var_t:file { getattr setattr create open read write rename };
Copy link
Contributor

Choose a reason for hiding this comment

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

var_t typically isn't used for files, since it is extremely generic, policy-wise. What dir(s)/file(s) are created?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looked into it further, it turns out we're moving the ssh key file location from /etc/ to /var/etc:

/var/etc/ssh/ssh_host_rsa_key.pub
/var/etc/ssh/ssh_host_rsa_key
/var/etc/ssh/ssh_host_ecdsa_key.pub
/var/etc/ssh/ssh_host_ecdsa_key
/var/etc/ssh/ssh_host_ed25519_key.pub
/var/etc/ssh/ssh_host_ed25519_key

This change is necessary for when verity is enabled and the etc location is read-only with a volatile overlay.

I'll drop the policy changes from the PR based on that. Thanks Chris.

@gmileka gmileka force-pushed the gmileka/unblock-iso-selinux branch 3 times, most recently from 4585c1e to 4573bf6 Compare February 11, 2025 22:12
@gmileka gmileka changed the title Update dracut module and selinux policy to enable selinux for liveos … Unblock SELinux for ISO - Update Dracut module to correctly locate selinux' 'chcon' Feb 11, 2025
@gmileka gmileka changed the title Unblock SELinux for ISO - Update Dracut module to correctly locate selinux' 'chcon' Unblock SELinux for ISO - Update Dracut module to correctly locate 'chcon' Feb 11, 2025
@gmileka gmileka force-pushed the gmileka/unblock-iso-selinux branch 2 times, most recently from adee260 to f482913 Compare February 11, 2025 22:34
@gmileka gmileka changed the title Unblock SELinux for ISO - Update Dracut module to correctly locate 'chcon' Dracut: Update Dracut overlay module to correctly locate 'chcon' Feb 11, 2025
@gmileka gmileka marked this pull request as ready for review February 11, 2025 22:42
@gmileka gmileka requested a review from a team as a code owner February 11, 2025 22:42
gmileka added a commit to microsoft/azure-linux-image-tools that referenced this pull request Feb 12, 2025
The logic in LiveOS ISO checks the Dracut version installed on the image
to be customized.

If it is below a certain version, it will always disable SELinux since
it knows SELinux is not supported for that version and the image will
not boot.

However, if it is at or higher, it leave SELinux as-is.

The problem is that this version is not set at 102-8, which has a known
bug blocking booting LiveOS ISO images when SELinux is enabled.

This change updates the version to a new Dracut package that has the fix
necessary for booting LiveOS ISO image with SELinux enabled.

See corresponding dracut change here:
microsoft/azurelinux#11986

<!-- Description: Please provide a summary of the changes and the
motivation behind them. -->

---

### **Checklist**
- [ ] Tests added/updated
- [ ] Documentation updated (if needed)
- [x] Code conforms to style guidelines
himaja-kesari pushed a commit to microsoft/azure-linux-image-tools that referenced this pull request Feb 26, 2025
The logic in LiveOS ISO checks the Dracut version installed on the image
to be customized.

If it is below a certain version, it will always disable SELinux since
it knows SELinux is not supported for that version and the image will
not boot.

However, if it is at or higher, it leave SELinux as-is.

The problem is that this version is not set at 102-8, which has a known
bug blocking booting LiveOS ISO images when SELinux is enabled.

This change updates the version to a new Dracut package that has the fix
necessary for booting LiveOS ISO image with SELinux enabled.

See corresponding dracut change here:
microsoft/azurelinux#11986

<!-- Description: Please provide a summary of the changes and the
motivation behind them. -->

---

### **Checklist**
- [ ] Tests added/updated
- [ ] Documentation updated (if needed)
- [x] Code conforms to style guidelines
himaja-kesari pushed a commit to microsoft/azure-linux-image-tools that referenced this pull request Feb 26, 2025
The logic in LiveOS ISO checks the Dracut version installed on the image
to be customized.

If it is below a certain version, it will always disable SELinux since
it knows SELinux is not supported for that version and the image will
not boot.

However, if it is at or higher, it leave SELinux as-is.

The problem is that this version is not set at 102-8, which has a known
bug blocking booting LiveOS ISO images when SELinux is enabled.

This change updates the version to a new Dracut package that has the fix
necessary for booting LiveOS ISO image with SELinux enabled.

See corresponding dracut change here:
microsoft/azurelinux#11986

<!-- Description: Please provide a summary of the changes and the
motivation behind them. -->

---

### **Checklist**
- [ ] Tests added/updated
- [ ] Documentation updated (if needed)
- [x] Code conforms to style guidelines
himaja-kesari pushed a commit to microsoft/azure-linux-image-tools that referenced this pull request Feb 26, 2025
The logic in LiveOS ISO checks the Dracut version installed on the image
to be customized.

If it is below a certain version, it will always disable SELinux since
it knows SELinux is not supported for that version and the image will
not boot.

However, if it is at or higher, it leave SELinux as-is.

The problem is that this version is not set at 102-8, which has a known
bug blocking booting LiveOS ISO images when SELinux is enabled.

This change updates the version to a new Dracut package that has the fix
necessary for booting LiveOS ISO image with SELinux enabled.

See corresponding dracut change here:
microsoft/azurelinux#11986

<!-- Description: Please provide a summary of the changes and the
motivation behind them. -->

---

### **Checklist**
- [ ] Tests added/updated
- [ ] Documentation updated (if needed)
- [x] Code conforms to style guidelines
himaja-kesari pushed a commit to microsoft/azure-linux-image-tools that referenced this pull request Feb 27, 2025
The logic in LiveOS ISO checks the Dracut version installed on the image
to be customized.

If it is below a certain version, it will always disable SELinux since
it knows SELinux is not supported for that version and the image will
not boot.

However, if it is at or higher, it leave SELinux as-is.

The problem is that this version is not set at 102-8, which has a known
bug blocking booting LiveOS ISO images when SELinux is enabled.

This change updates the version to a new Dracut package that has the fix
necessary for booting LiveOS ISO image with SELinux enabled.

See corresponding dracut change here:
microsoft/azurelinux#11986

<!-- Description: Please provide a summary of the changes and the
motivation behind them. -->

---

### **Checklist**
- [ ] Tests added/updated
- [ ] Documentation updated (if needed)
- [x] Code conforms to style guidelines
himaja-kesari pushed a commit to microsoft/azure-linux-image-tools that referenced this pull request Feb 27, 2025
The logic in LiveOS ISO checks the Dracut version installed on the image
to be customized.

If it is below a certain version, it will always disable SELinux since
it knows SELinux is not supported for that version and the image will
not boot.

However, if it is at or higher, it leave SELinux as-is.

The problem is that this version is not set at 102-8, which has a known
bug blocking booting LiveOS ISO images when SELinux is enabled.

This change updates the version to a new Dracut package that has the fix
necessary for booting LiveOS ISO image with SELinux enabled.

See corresponding dracut change here:
microsoft/azurelinux#11986

<!-- Description: Please provide a summary of the changes and the
motivation behind them. -->

---

### **Checklist**
- [ ] Tests added/updated
- [ ] Documentation updated (if needed)
- [x] Code conforms to style guidelines
…ate 'chcon'

We now use the full path of 'chcon' to ensure we always find it regardless of the
contents of initrd.
@gmileka gmileka force-pushed the gmileka/unblock-iso-selinux branch from f482913 to d88a7cb Compare March 6, 2025 00:06
Copy link
Contributor

@romoh romoh left a comment

Choose a reason for hiding this comment

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

LGTM

@gmileka gmileka merged commit 36b2761 into 3.0-dev Mar 10, 2025
14 checks passed
@gmileka gmileka deleted the gmileka/unblock-iso-selinux branch March 10, 2025 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.0-dev PRs Destined for AzureLinux 3.0 Packaging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants