Skip to content

WIP: Port osmodifier from Go binary to native Rust crate#638

Draft
bfjelds wants to merge 12 commits into
mainfrom
user/bfjelds/mjolnir/port-osmodifier-to-rust
Draft

WIP: Port osmodifier from Go binary to native Rust crate#638
bfjelds wants to merge 12 commits into
mainfrom
user/bfjelds/mjolnir/port-osmodifier-to-rust

Conversation

@bfjelds
Copy link
Copy Markdown
Member

@bfjelds bfjelds commented May 11, 2026

Replace the external Go osmodifier binary from azure-linux-image-tools with a native Rust library crate (crates/osmodifier). Trident now calls osmodifier functions directly instead of serializing config to YAML, writing a temp file, and exec'ing the Go binary.

@bfjelds
Copy link
Copy Markdown
Member Author

bfjelds commented May 11, 2026

/azp run [GITHUB]-trident-pr-e2e

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@bfjelds bfjelds changed the title Port osmodifier from Go binary to native Rust crate WIP: Port osmodifier from Go binary to native Rust crate May 11, 2026
@bfjelds
Copy link
Copy Markdown
Member Author

bfjelds commented May 11, 2026

/azp run [GITHUB]-trident-pr-e2e

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@bfjelds
Copy link
Copy Markdown
Member Author

bfjelds commented May 11, 2026

/azp run [GITHUB]-trident-pr-e2e

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@bfjelds bfjelds force-pushed the user/bfjelds/mjolnir/port-osmodifier-to-rust branch 3 times, most recently from 9fff08e to 2fb0625 Compare May 11, 2026 21:27
@bfjelds
Copy link
Copy Markdown
Member Author

bfjelds commented May 11, 2026

/azp run [GITHUB]-trident-pr

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@bfjelds
Copy link
Copy Markdown
Member Author

bfjelds commented May 11, 2026

/azp run [GITHUB]-trident-pr-e2e

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@bfjelds
Copy link
Copy Markdown
Member Author

bfjelds commented May 12, 2026

/azp run [GITHUB]-trident-pr-e2e

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@bfjelds
Copy link
Copy Markdown
Member Author

bfjelds commented May 12, 2026

/azp run [GITHUB]-trident-pr-e2e

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@bfjelds bfjelds force-pushed the user/bfjelds/mjolnir/port-osmodifier-to-rust branch 5 times, most recently from becb22b to ccabced Compare May 14, 2026 16:25
@bfjelds
Copy link
Copy Markdown
Member Author

bfjelds commented May 14, 2026

/azp run [GITHUB]-trident-pr-e2e

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command.

@bfjelds
Copy link
Copy Markdown
Member Author

bfjelds commented May 14, 2026

/azp run [GITHUB]-trident-pr-e2e

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command.

bfjelds and others added 3 commits May 14, 2026 09:41
Replace the external Go osmodifier binary from azure-linux-image-tools
with a native Rust library crate (crates/osmodifier). Trident now calls
osmodifier functions directly instead of serializing config to YAML,
writing a temp file, and exec'ing the Go binary.

The new crate implements:
- User management (useradd, password hashing, SSH keys, groups)
- Hostname configuration (/etc/hostname)
- Service management (systemctl enable/disable)
- Kernel module configuration (modules-load.d, modprobe.d)
- SELinux configuration (/etc/selinux/config and kernel cmdline)
- /etc/default/grub parsing and writing
- grub.cfg parsing for update-default-grub flow
- grub2-mkconfig execution

Public API:
- modify_os() - replaces osmodifier --config-file for OS modifications
- update_default_grub() - replaces osmodifier --update-grub
- modify_boot() - replaces osmodifier --config-file for boot config

This eliminates:
- External Go binary build dependency (azure-linux-image-tools clone)
- Binary bind-mounting into newroot
- YAML serialization round-trip overhead
- OS_MODIFIER_BINARY_PATH and OS_MODIFIER_NEWROOT_PATH constants
- Makefile, Dockerfile, RPM spec, and pipeline osmodifier references

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ed import

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…l tests

Remove all download-osmodifier.yml template invocations, make
artifacts/osmodifier targets, and functional test binary upload steps.
The osmodifier is now compiled into the trident binary as a library crate.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
bfjelds and others added 7 commits May 14, 2026 09:42
- Add back std::path::Path import in osconfig/mod.rs (needed for
  provision() signature)
- Remove unused crate::engine::EngineContext import in newroot.rs
- Remove unused std::path::Path import in boot/mod.rs

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Fixes based on 9-agent adversarial code review:

Security:
- Use chpasswd -e via stdin instead of useradd -p to avoid leaking
  password hashes through /proc/cmdline
- Validate startup_command for colons/newlines to prevent /etc/passwd
  corruption
- Implement PasswordType::Locked for existing users (write ! marker)

Atomicity:
- All /etc/shadow and /etc/passwd edits now use atomic write-temp-rename
  pattern via tempfile::NamedTempFile::persist()

Correctness:
- Fix set_password_expiry: add missing found-check (was silent no-op)
- Fix add_extra_cmdline: deduplicate by key to be idempotent on re-run
- Fix stale comment in modify_os about not touching grub

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The Go osmodifier wrote hostname without trailing newline. The Rust
port added one, causing the functional test assertion to fail:
  left: 'carry-over-hostname\n' right: 'carry-over-hostname'

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add Rust functional tests for the osmodifier modules that run inside
the test VM. Tests cover:

- hostname: write and overwrite /etc/hostname
- modules: always-load, disable, options, idempotency, disable-removes-load
- selinux: config file update (enforcing/disabled), missing file error,
  GRUB cmdline SELinux args
- services: enable/disable with synthetic systemd units, already-disabled
- lib.rs integration: modify_os with hostname+modules, empty config no-op,
  hostname+services combined

All tests use tempdir-rooted OsModifierContext to avoid modifying the
real system. Service tests use synthetic unit files rather than depending
on installed services.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@bfjelds bfjelds force-pushed the user/bfjelds/mjolnir/port-osmodifier-to-rust branch from ccabced to 23ca4c8 Compare May 14, 2026 16:42
@bfjelds
Copy link
Copy Markdown
Member Author

bfjelds commented May 14, 2026

/azp run [GITHUB]-trident-pr-e2e

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@bfjelds
Copy link
Copy Markdown
Member Author

bfjelds commented May 14, 2026

/azp run [GITHUB]-trident-pr-e2e

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@bfjelds
Copy link
Copy Markdown
Member Author

bfjelds commented May 14, 2026

/azp run [GITHUB]-trident-pr-e2e

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant