Skip to content

internal/controller: ensure $HOME is set for atlas-cli#354

Merged
giautm merged 1 commit intomasterfrom
g/home-dir
Apr 3, 2026
Merged

internal/controller: ensure $HOME is set for atlas-cli#354
giautm merged 1 commit intomasterfrom
g/home-dir

Conversation

@giautm
Copy link
Copy Markdown
Member

@giautm giautm commented Apr 3, 2026

No description provided.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the controller’s Atlas CLI execution environment setup to ensure HOME is configured, and adjusts controller tests to provide a DATA_DIR during runs.

Changes:

  • Changed NewAtlasExec to always derive HOME from a DATA_DIR (defaulting to /data) and create the directory.
  • Updated AtlasSchema controller tests to set DATA_DIR to a temporary directory.
  • Updated AtlasMigration controller tests to set DATA_DIR to a temporary directory.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
internal/controller/common.go Changes how Atlas CLI environment is prepared by defaulting DATA_DIR and always setting HOME under it.
internal/controller/atlasschema_controller_test.go Sets DATA_DIR in tests to avoid writing to real filesystem locations.
internal/controller/atlasmigration_controller_test.go Sets DATA_DIR in tests to avoid writing to real filesystem locations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +105 to +109
dataDir := os.Getenv(envDataDir)
if dataDir == "" {
// If DATA_DIR is not set, use /tmp/data
// as the default directory for storing Atlas CLI data.
dataDir = "/tmp/data"
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

The function-level comment above still says HOME is only set when DATA_DIR is set, but the updated logic always chooses a dataDir (defaulting to "/tmp/data") and always sets HOME. Please update the comment to match the new behavior and document the default path when DATA_DIR is unset.

Copilot uses AI. Check for mistakes.
Comment on lines +111 to +115
homeDir := filepath.Join(dataDir, home)
if err := os.MkdirAll(homeDir, 0755); err != nil {
return nil, fmt.Errorf("creating resource home directory: %w", err)
}
env["HOME"] = homeDir
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

This now unconditionally overrides any existing HOME from the inherited environment. Previously, if DATA_DIR was unset, an existing HOME would be preserved. If the goal is only to ensure HOME is non-empty, consider only setting HOME when it’s missing (or make the override explicit via a separate env var/flag) to avoid surprising behavior changes for local/dev runs.

Copilot uses AI. Check for mistakes.
dataDir = "/tmp/data"
}
homeDir := filepath.Join(dataDir, home)
if err := os.MkdirAll(homeDir, 0755); err != nil {
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

The directory used as Atlas CLI HOME may contain credentials/config under ~/.atlas. Creating it with mode 0755 makes it readable/traversable by other users in the same container/node. Consider using a more restrictive mode (e.g., 0700) for the HOME directory.

Suggested change
if err := os.MkdirAll(homeDir, 0755); err != nil {
if err := os.MkdirAll(homeDir, 0700); err != nil {

Copilot uses AI. Check for mistakes.
@giautm giautm merged commit 877abc5 into master Apr 3, 2026
4 checks passed
@giautm giautm deleted the g/home-dir branch April 3, 2026 16:41
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.

4 participants