feat(lxc): implement idmap support via SSH config file editing#2579
feat(lxc): implement idmap support via SSH config file editing#2579
Conversation
Summary of ChangesHello @LTe, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This is a great feature addition, enabling idmap support for LXC containers. The implementation via SSH to work around API limitations is a clever solution. The code is well-structured, and the inclusion of comprehensive acceptance tests is excellent. I have one suggestion to improve the robustness of parsing idmap entries from the API response.
The Proxmox REST API does not support writing lxc[n] parameters (like lxc.idmap) - it rejects them with "property is not defined in schema". The API can read these entries but not write them. Switch idmap CRUD operations to edit /etc/pve/lxc/<vmid>.conf directly via SSH, following the same pattern used for VM disk imports in disk.go. The API read path remains unchanged since GET returns lxc entries. Signed-off-by: Piotr Niełacny <[email protected]>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces valuable idmap support for LXC containers, and the SSH-based workaround for the API limitation is a practical approach. However, there are a couple of significant issues that need to be addressed before this can be merged.
Critical Issues:
- Architectural Violation: This feature is implemented in the legacy SDK provider (
proxmoxtf), but the project's contribution guidelines (GEMINI.md, line 51) require new features to be implemented in the modern Framework provider (fwprovider/) only. The acceptance tests are correctly placed infwprovider/test, but the corresponding resource implementation for the framework provider is missing. This needs to be corrected. - Data Loss in API Parsing: The custom JSON unmarshaler for
idmapentries discards all otherlxc.*properties returned by the Proxmox API. This will break any functionality that relies on reading other LXC settings and should be fixed to avoid data loss. I've added a specific comment on this.
Suggestions:
- Command Atomicity: The SSH commands used to update the container configuration file are not atomic. I've left a suggestion to improve the robustness of this operation by combining multiple commands into one.
Restructure CustomIDMaps into CustomLXCConfig struct that holds both the raw [][2]string from the API and the parsed idmap entries. This prevents silent data loss of non-idmap LXC configuration entries (e.g. lxc.cgroup2.*, lxc.cap.drop) during JSON unmarshaling. Signed-off-by: Piotr Niełacny <[email protected]>
Consolidate per-entry SSH tee commands into a single write operation to avoid leaving the config file in an inconsistent state if a command fails mid-way. Signed-off-by: Piotr Niełacny <[email protected]>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces support for idmap in LXC containers by modifying the configuration file via SSH. The implementation is well-structured, includes thorough tests for both the parsing logic and the resource lifecycle, and updates the documentation. However, there is a critical concern regarding the project's architecture: the new feature is implemented in the legacy SDK provider, which contradicts the contribution guidelines stating that new features should be added to the modern framework provider. The implementation for the framework provider appears to be missing in this PR.
Signed-off-by: Pavel Boldyrev <[email protected]>
bpg-dev
left a comment
There was a problem hiding this comment.
Thanks a lot @LTe for contributing this, solid work! ❤️
I made a few tweaks in the flow to ensure the ssh config update happens after the config file unlock, to prevent conflicts / overrides by PVE.
Also added the new requirements to sudoers file in docs.
LGTM! 🚀
|
@all-contributors please add @LTe for code |
|
I've put up a pull request to add @LTe! 🎉 |
What does this PR do?
Adds
idmapblock support to theproxmox_virtual_environment_containerresource, enabling UID/GID mapping configuration for unprivileged LXC containers.The Proxmox API does not support writing
lxc[n]parameters, solxc.idmapentries cannot be set through the standard API. This implementation writes idmap entries directly to/etc/pve/lxc/<vmid>.confvia SSH after container creation or update, reads them back through the API'slxcconfig field, and manages full lifecycle (create, update, remove).Contributor's Note
make lintand fixed any issues.make docs; SDK: manual/docs/edits).!in PR title).make exampleto verify the change works (mainly for SDK / provider config changes).Proof of Work
Acceptance test
TestAccResourceContainerIDMappasses — covers create (2 idmap entries), update (modify + add entries), and remove (clear all entries). Each step verifies no perpetual diffs.Step 1 — Create: Container created via API, idmap written via SSH, API read-back confirms:
{"lxc": [["lxc.idmap", "u 0 100000 65536"], ["lxc.idmap", "g 0 100000 65536"]]}SSH commands executed
Step 2 — Update: GID mapping modified, additional entry added, API read-back confirms:
{"lxc": [["lxc.idmap", "u 0 100000 65536"], ["lxc.idmap", "g 0 100000 44"], ["lxc.idmap", "g 44 44 1"]]}Step 3 — Remove: All idmap blocks removed, API read-back has no
lxcfield — entries fully cleared.Lint passes with 0 issues in the changed files.
Community Note
Relates #256
Relates #1801