Skip to content

Commit eeee545

Browse files
committed
vmm-cli: require --kms and --kms-url when using --env-file
Add validation to ensure KMS is properly configured when --env-file is used: 1. compose command: --env-file requires --kms flag 2. deploy command: --env-file requires both --kms-url and kms_enabled=true in compose 3. update command: --env-file requires --kms-url 4. update-env command: requires --kms-url Environment variables need KMS to be enabled for decryption inside the VM, and need --kms-url to encrypt them before sending.
1 parent 139d588 commit eeee545

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

vmm/src/vmm-cli.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,11 @@ def calc_app_id(self, compose_file: str) -> str:
520520
def create_app_compose(self, args) -> None:
521521
"""Create a new app compose file"""
522522
envs = parse_env_file(args.env_file) or {}
523+
524+
# Validate: --env-file requires --kms
525+
if envs and not args.kms:
526+
raise Exception("--env-file requires --kms to enable KMS for environment variable decryption")
527+
523528
app_compose = {
524529
"manifest_version": 2,
525530
"name": args.name,
@@ -565,6 +570,17 @@ def create_vm(self, args) -> None:
565570

566571
envs = parse_env_file(args.env_file)
567572

573+
# Validate: --env-file requires --kms-url and kms_enabled in compose
574+
if envs:
575+
if not args.kms_url:
576+
raise Exception("--env-file requires --kms-url to encrypt environment variables")
577+
try:
578+
compose_json = json.loads(compose_content)
579+
if not compose_json.get('kms_enabled', False):
580+
raise Exception("--env-file requires kms_enabled=true in the compose file (use --kms when creating compose)")
581+
except json.JSONDecodeError:
582+
pass # Let the server handle invalid JSON
583+
568584
# Read user config file if provided
569585
user_config = ""
570586
if args.user_config:
@@ -620,6 +636,10 @@ def create_vm(self, args) -> None:
620636

621637
def update_vm_env(self, vm_id: str, envs: Dict[str, str], kms_urls: Optional[List[str]] = None) -> None:
622638
"""Update environment variables for a VM"""
639+
# Validate: requires --kms-url
640+
if not kms_urls:
641+
raise Exception("--kms-url is required to encrypt environment variables")
642+
623643
envs = envs or {}
624644
# First get the VM info to retrieve the app_id
625645
vm_info_response = self.rpc_call('GetInfo', {'id': vm_id})
@@ -709,6 +729,10 @@ def update_vm(
709729
no_tee: Optional[bool] = None,
710730
) -> None:
711731
"""Update multiple aspects of a VM in one command"""
732+
# Validate: --env-file requires --kms-url
733+
if env_file and not kms_urls:
734+
raise Exception("--env-file requires --kms-url to encrypt environment variables")
735+
712736
updates = []
713737

714738
# handle resize operations (vcpu, memory, disk, image)

0 commit comments

Comments
 (0)