Skip to content

SC CLI crashes with nil pointer when running provision outside git repository #54

@alex-y-su

Description

@alex-y-su

Description

When running sc provision in a directory that is not a git repository, the CLI crashes with a nil pointer dereference (SIGSEGV). This prevents using SC CLI in cloud orchestration scenarios where config files are dynamically generated in temporary directories.

SC Version

2025.12.2

Steps to Reproduce

  1. Create a temporary directory (not a git repo):
mkdir -p /tmp/sc-test-stack
cd /tmp/sc-test-stack
  1. Create server.yaml:
schemaVersion: "1.0"
provisioner:
  type: pulumi
  config:
    state-storage:
      type: gcp-bucket
      config:
        credentials: "${auth:gcloud}"
        projectId: "${auth:gcloud.projectId}"
        provision: true
        name: sc-state-my-bucket
        location: US
    secrets-provider:
      type: passphrase
      config:
        passPhrase: my-secret-passphrase

resources:
  resources:
    default:
      resources:
        my-bucket:
          type: gcp-bucket
          config:
            projectId: "${auth:gcloud.projectId}"
            credentials: "${auth:gcloud}"
            name: my-bucket
            location: US
  1. Create secrets.yaml:
schemaVersion: "1.0"
auth:
  gcloud:
    type: gcp-service-account
    config:
      projectId: my-project-id
      credentials: |
        {
          "type": "service_account",
          "project_id": "my-project-id",
          "private_key_id": "...",
          "private_key": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n",
          "client_email": "my-sa@my-project-id.iam.gserviceaccount.com",
          "client_id": "...",
          "auth_uri": "https://accounts.google.com/o/oauth2/auth",
          "token_uri": "https://oauth2.googleapis.com/token",
          "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
          "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/...",
          "universe_domain": "googleapis.com"
        }
  1. Run provision:
sc provision --dir /tmp/sc-test-stack

Expected Behavior

SC CLI should either:

  1. Work without requiring a git repository
  2. Provide a clear error message if git repository is required

Actual Behavior

SC CLI crashes with a segmentation fault:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x88 pc=0x1063bccf0]

goroutine 1 [running]:
github.com/simple-container-com/api/pkg/cmd/cmd_provision.NewProvisionCmd.func1(0x1400381db08?, {0x10641209d?, 0x4?, 0x1064120a1?})
	/home/runner/_work/api/api/pkg/cmd/cmd_provision/cmd_provision.go:40 +0xd0
github.com/spf13/cobra.(*Command).execute(0x1400381db08, {0x140038085a0, 0x2, 0x2})
	/home/runner/go/pkg/mod/github.com/spf13/cobra@v1.9.1/command.go:1015 +0x844
github.com/spf13/cobra.(*Command).ExecuteC(0x140001b1208)
	/home/runner/go/pkg/mod/github.com/spf13/cobra@v1.9.1/command.go:1148 +0x384
github.com/spf13/cobra.(*Command).Execute(...)
	/home/runner/go/pkg/mod/github.com/spf13/cobra@v1.9.1/command.go:1071
main.main()
	/home/runner/_work/api/api/cmd/sc/main.go:91 +0x5e0

Use Case

We are building a cloud orchestration platform that:

  1. Receives resource creation requests via API
  2. Dynamically generates SC config files in temporary directories
  3. Calls sc provision to create the resources

In this scenario, config files are generated programmatically and there is no git repository involved.

Suggested Fix

The crash occurs at cmd_provision.go:40. The code likely assumes git repository context exists and does not handle the case when it is nil. Please add a nil check or make git repository optional for provision operations.

Environment

  • OS: macOS (Darwin 25.0.0)
  • Architecture: ARM64
  • SC Version: 2025.12.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions