Skip to content

Conversation

@ytimocin
Copy link
Contributor

@ytimocin ytimocin commented Apr 15, 2025

Description

This pull request introduces significant enhancements and new features across multiple areas, including Kubernetes deployment, configuration management, and development environment initialization. Key changes include adding support for air-gapped environments, refining Kubernetes installation options, and improving the handling of provisioning states in resources.

Kubernetes Deployment Enhancements:

  • Added the ability to disable the Contour ingress controller during Radius installation (pkg/cli/cmd/install/kubernetes/kubernetes.go). [1] [2] [3] [4]
  • Updated the deploy-local.sh script to automate building, pushing Docker images, resetting the Kubernetes cluster, and publishing Bicep extensions (deploy-local.sh).

Air-Gapped Environment Support:

  • Introduced the --recipe-registry flag in the rad init command to specify an alternative container registry for dev recipes (pkg/cli/cmd/radinit/init.go). [1] [2] [3] [4]
  • Modified the GetDevRecipes method to accept a recipeRegistry parameter for fetching recipes from a custom registry (pkg/cli/cmd/radinit/mock_devrecipeclient.go, pkg/cli/cmd/radinit/environment.go). [1] [2] [3]

Configuration Improvements:

  • Added new parameters and resources to the app-kubernetes-postgres.bicep file for managing secrets, authentication, and registry settings (app-kubernetes-postgres.bicep).
  • Updated the bicepconfig.json file to use a local extension path instead of a registry reference (bicepconfig.json).

Resource Management:

  • Refactored the ProvisioningState methods in BaseResource to use a simpler structure (pkg/armrpc/api/v1/types.go).

Testing and Mock Updates:

  • Adjusted tests and mocks to support the new recipeRegistry parameter (pkg/cli/cmd/radinit/init_test.go, pkg/cli/cmd/radinit/mock_devrecipeclient.go). [1] [2] [3]

Type of change

  • This pull request adds or changes features of Radius and has an approved issue (issue link required).

Fixes: #issue_number

Contributor checklist

Please verify that the PR meets the following requirements, where applicable:

  • An overview of proposed schema changes is included in a linked GitHub issue.
    • Yes
    • Not applicable
  • A design document PR is created in the design-notes repository, if new APIs are being introduced.
    • Yes
    • Not applicable
  • The design document has been reviewed and approved by Radius maintainers/approvers.
    • Yes
    • Not applicable
  • A PR for the samples repository is created, if existing samples are affected by the changes in this PR.
    • Yes
    • Not applicable
  • A PR for the documentation repository is created, if the changes in this PR affect the documentation or any user facing updates are made.
    • Yes
    • Not applicable
  • A PR for the recipes repository is created, if existing recipes are affected by the changes in this PR.
    • Yes
    • Not applicable

@ytimocin
Copy link
Contributor Author

The gist that installs Radius on an air-gapped cluster: https://gist.github.com/ytimocin/8887d95ab1409562f4646fd30edb101c. Still WIP and needs to be updated.

@radius-functional-tests
Copy link

radius-functional-tests bot commented Apr 15, 2025

Radius functional test overview

🔍 Go to test action run

Name Value
Repository radius-project/radius
Commit ref ec13934
Unique ID funcb1c95443e8
Image tag pr-funcb1c95443e8
Click here to see the list of tools in the current test run
  • gotestsum 1.12.0
  • KinD: v0.20.0
  • Dapr:
  • Azure KeyVault CSI driver: 1.4.2
  • Azure Workload identity webhook: 1.3.0
  • Bicep recipe location ghcr.io/radius-project/dev/test/testrecipes/test-bicep-recipes/<name>:pr-funcb1c95443e8
  • Terraform recipe location http://tf-module-server.radius-test-tf-module-server.svc.cluster.local/<name>.zip (in cluster)
  • applications-rp test image location: ghcr.io/radius-project/dev/applications-rp:pr-funcb1c95443e8
  • dynamic-rp test image location: ghcr.io/radius-project/dev/dynamic-rp:pr-funcb1c95443e8
  • controller test image location: ghcr.io/radius-project/dev/controller:pr-funcb1c95443e8
  • ucp test image location: ghcr.io/radius-project/dev/ucpd:pr-funcb1c95443e8
  • deployment-engine test image location: ghcr.io/radius-project/deployment-engine:latest

Test Status

⌛ Building Radius and pushing container images for functional tests...
✅ Container images build succeeded
⌛ Publishing Bicep Recipes for functional tests...
✅ Recipe publishing succeeded
⌛ Starting ucp-cloud functional tests...
⌛ Starting corerp-cloud functional tests...
✅ ucp-cloud functional tests succeeded
✅ corerp-cloud functional tests succeeded

commonflags.AddKubeContextFlagVar(cmd, &runner.KubeContext)
cmd.Flags().BoolVar(&runner.Reinstall, "reinstall", false, "Specify to force reinstallation of Radius")
cmd.Flags().StringVar(&runner.Chart, "chart", "", "Specify a file path to a helm chart to install Radius from")
cmd.Flags().StringVar(&runner.ContourChart, "contour-chart", "", "Specify a local file path to a helm chart to install Contour from")
Copy link
Contributor

Choose a reason for hiding this comment

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

do these have to be a local filepath or can they be an OCI registry (e.g. on a local CR)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

local path for now

options.Radius.ChartPath = cliOptions.Radius.ChartPath
}

if cliOptions.Radius.ChartRepo != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

was this missing before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes

if err != nil {
return fmt.Errorf("failed to get contour chart, err: %w, helm output: %s", err, helmOutput.String())
// Use provided repo URL if available, otherwise use default
repo := options.ChartRepo
Copy link
Contributor

Choose a reason for hiding this comment

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

can probably remove this codeblock, looks like dupe of below

@ytimocin ytimocin force-pushed the ytimocin/air-gapped-cluster branch from ec13934 to 3bacc6f Compare April 15, 2025 21:13
Copy link
Contributor

@willdavsmith willdavsmith left a comment

Choose a reason for hiding this comment

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

nice, I think this is the right place to add these changes. my only question is if we need to support loading a helm chart from a local container registry instead of a local file

@github-actions
Copy link

github-actions bot commented Apr 15, 2025

Unit Tests

3 959 tests  +106   3 955 ✅ +106   9m 27s ⏱️ + 2m 22s
  307 suites +  3       4 💤 ±  0 
    1 files   ±  0       0 ❌ ±  0 

Results for commit c847ea5. ± Comparison against base commit e54aef5.

This pull request removes 84 and adds 190 tests. Note that renamed tests count towards both.
github.com/radius-project/radius/pkg/recipes/driver ‑ TestAddConfig
github.com/radius-project/radius/pkg/recipes/driver ‑ TestAddConfig/invalid_git_url
github.com/radius-project/radius/pkg/recipes/driver ‑ TestAddConfig/success
github.com/radius-project/radius/pkg/recipes/driver ‑ TestSetGitConfigForDir
github.com/radius-project/radius/pkg/recipes/driver ‑ TestSetGitConfigForDir/success
github.com/radius-project/radius/pkg/recipes/driver ‑ TestTerraformDriver_GetRecipeMetadata_Failure
github.com/radius-project/radius/pkg/recipes/driver ‑ TestTerraformDriver_GetRecipeMetadata_Success
github.com/radius-project/radius/pkg/recipes/driver ‑ TestUnsetGitConfigForDir
github.com/radius-project/radius/pkg/recipes/driver ‑ TestUnsetGitConfigForDir/success
github.com/radius-project/radius/pkg/recipes/driver ‑ Test_Bicep_Delete_Error
…
github.com/radius-project/radius/pkg/corerp/api/v20231001preview ‑ TestConvertDataModelToVersioned/environmentresourcedatamodel-terraform-auth.json
github.com/radius-project/radius/pkg/corerp/api/v20231001preview ‑ TestConvertDataModelToVersioned/environmentresourcedatamodel-terraform-pat.json
github.com/radius-project/radius/pkg/corerp/api/v20231001preview ‑ TestConvertDataModelToVersioned/environmentresourcedatamodel-terraform-registry-additionalhosts.json
github.com/radius-project/radius/pkg/corerp/api/v20231001preview ‑ TestConvertDataModelToVersioned/environmentresourcedatamodel-terraform-tls.json
github.com/radius-project/radius/pkg/corerp/api/v20231001preview ‑ TestConvertVersionedToDataModel/environmentresource-terraform-auth.json
github.com/radius-project/radius/pkg/corerp/api/v20231001preview ‑ TestConvertVersionedToDataModel/environmentresource-terraform-pat.json
github.com/radius-project/radius/pkg/corerp/api/v20231001preview ‑ TestConvertVersionedToDataModel/environmentresource-terraform-registry-additionalhosts.json
github.com/radius-project/radius/pkg/corerp/api/v20231001preview ‑ TestConvertVersionedToDataModel/environmentresource-terraform-tls.json
github.com/radius-project/radius/pkg/corerp/api/v20231001preview ‑ Test_toFromTLSConfigDatamodel
github.com/radius-project/radius/pkg/corerp/api/v20231001preview ‑ Test_toFromTLSConfigDatamodel/No_TLS_config
…

♻️ This comment has been updated with latest results.

@nithyatsu
Copy link
Contributor

Nice, LGTM. This will be a one off or would we officially support these options in main?

@radius-functional-tests
Copy link

radius-functional-tests bot commented Apr 23, 2025

Radius functional test overview

🔍 Go to test action run

Name Value
Repository radius-project/radius
Commit ref 205332c
Unique ID funce793ade198
Image tag pr-funce793ade198
Click here to see the list of tools in the current test run
  • gotestsum 1.12.0
  • KinD: v0.20.0
  • Dapr:
  • Azure KeyVault CSI driver: 1.4.2
  • Azure Workload identity webhook: 1.3.0
  • Bicep recipe location ghcr.io/radius-project/dev/test/testrecipes/test-bicep-recipes/<name>:pr-funce793ade198
  • Terraform recipe location http://tf-module-server.radius-test-tf-module-server.svc.cluster.local/<name>.zip (in cluster)
  • applications-rp test image location: ghcr.io/radius-project/dev/applications-rp:pr-funce793ade198
  • dynamic-rp test image location: ghcr.io/radius-project/dev/dynamic-rp:pr-funce793ade198
  • controller test image location: ghcr.io/radius-project/dev/controller:pr-funce793ade198
  • ucp test image location: ghcr.io/radius-project/dev/ucpd:pr-funce793ade198
  • deployment-engine test image location: ghcr.io/radius-project/deployment-engine:latest

Test Status

⌛ Building Radius and pushing container images for functional tests...
✅ Container images build succeeded
⌛ Publishing Bicep Recipes for functional tests...
✅ Recipe publishing succeeded
⌛ Starting corerp-cloud functional tests...
⌛ Starting ucp-cloud functional tests...
✅ corerp-cloud functional tests succeeded
✅ ucp-cloud functional tests succeeded

@codecov
Copy link

codecov bot commented Apr 23, 2025

Codecov Report

Attention: Patch coverage is 49.09639% with 1014 lines in your changes missing coverage. Please review.

Project coverage is 49.37%. Comparing base (e54aef5) to head (c847ea5).
Report is 23 commits behind head on main.

Files with missing lines Patch % Lines
...s/terraform/customsource/custom_registry_source.go 43.98% 190 Missing and 38 partials ⚠️
pkg/recipes/driver/terraform/registry.go 56.74% 138 Missing and 16 partials ⚠️
pkg/recipes/terraform/customsource/helper.go 3.47% 139 Missing ⚠️
pkg/recipes/terraform/execute.go 42.22% 94 Missing and 10 partials ⚠️
pkg/recipes/terraform/install.go 49.44% 83 Missing and 8 partials ⚠️
pkg/recipes/driver/terraform/terraform.go 41.12% 57 Missing and 16 partials ⚠️
...erp/api/v20231001preview/environment_conversion.go 68.06% 53 Missing and 8 partials ⚠️
pkg/cli/helm/cluster.go 6.66% 19 Missing and 9 partials ⚠️
pkg/cli/helm/contour.go 23.07% 17 Missing and 3 partials ⚠️
pkg/cli/cmd/radinit/recipe.go 0.00% 18 Missing ⚠️
... and 16 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9189      +/-   ##
==========================================
+ Coverage   49.36%   49.37%   +0.01%     
==========================================
  Files         636      640       +4     
  Lines       48757    50612    +1855     
==========================================
+ Hits        24067    24992     +925     
- Misses      22860    23669     +809     
- Partials     1830     1951     +121     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ytimocin ytimocin force-pushed the ytimocin/air-gapped-cluster branch from 205332c to edb52e7 Compare April 25, 2025 15:15
@ytimocin ytimocin force-pushed the ytimocin/air-gapped-cluster branch from 9e8db98 to 469cf36 Compare April 29, 2025 20:37
@radius-functional-tests
Copy link

radius-functional-tests bot commented Jun 27, 2025

Radius functional test overview

🔍 Go to test action run

Name Value
Repository radius-project/radius
Commit ref 71a1d32
Unique ID func5a7b2644aa
Image tag pr-func5a7b2644aa
Click here to see the list of tools in the current test run
  • gotestsum 1.12.0
  • KinD: v0.20.0
  • Dapr:
  • Azure KeyVault CSI driver: 1.4.2
  • Azure Workload identity webhook: 1.3.0
  • Bicep recipe location ghcr.io/radius-project/dev/test/testrecipes/test-bicep-recipes/<name>:pr-func5a7b2644aa
  • Terraform recipe location http://tf-module-server.radius-test-tf-module-server.svc.cluster.local/<name>.zip (in cluster)
  • applications-rp test image location: ghcr.io/radius-project/dev/applications-rp:pr-func5a7b2644aa
  • dynamic-rp test image location: ghcr.io/radius-project/dev/dynamic-rp:pr-func5a7b2644aa
  • controller test image location: ghcr.io/radius-project/dev/controller:pr-func5a7b2644aa
  • ucp test image location: ghcr.io/radius-project/dev/ucpd:pr-func5a7b2644aa
  • deployment-engine test image location: ghcr.io/radius-project/deployment-engine:latest

Test Status

⌛ Building Radius and pushing container images for functional tests...
✅ Container images build succeeded
⌛ Publishing Bicep Recipes for functional tests...
✅ Recipe publishing succeeded
⌛ Starting corerp-cloud functional tests...
⌛ Starting ucp-cloud functional tests...
✅ ucp-cloud functional tests succeeded
✅ corerp-cloud functional tests succeeded

@ytimocin ytimocin force-pushed the ytimocin/air-gapped-cluster branch from 71a1d32 to dfe0571 Compare July 1, 2025 14:56
…he credentials in the terraformrc file.

Signed-off-by: ytimocin <[email protected]>
@ytimocin ytimocin force-pushed the ytimocin/air-gapped-cluster branch from dfe0571 to eede0c9 Compare July 1, 2025 15:05
@ytimocin ytimocin temporarily deployed to functional-tests July 1, 2025 15:11 — with GitHub Actions Inactive
@ytimocin ytimocin temporarily deployed to publish-bicep July 1, 2025 15:11 — with GitHub Actions Inactive
@radius-functional-tests
Copy link

radius-functional-tests bot commented Jul 1, 2025

Radius functional test overview

🔍 Go to test action run

Name Value
Repository radius-project/radius
Commit ref 58e0b64
Unique ID func4dfb143941
Image tag pr-func4dfb143941
Click here to see the list of tools in the current test run
  • gotestsum 1.12.0
  • KinD: v0.20.0
  • Dapr:
  • Azure KeyVault CSI driver: 1.4.2
  • Azure Workload identity webhook: 1.3.0
  • Bicep recipe location ghcr.io/radius-project/dev/test/testrecipes/test-bicep-recipes/<name>:pr-func4dfb143941
  • Terraform recipe location http://tf-module-server.radius-test-tf-module-server.svc.cluster.local/<name>.zip (in cluster)
  • applications-rp test image location: ghcr.io/radius-project/dev/applications-rp:pr-func4dfb143941
  • dynamic-rp test image location: ghcr.io/radius-project/dev/dynamic-rp:pr-func4dfb143941
  • controller test image location: ghcr.io/radius-project/dev/controller:pr-func4dfb143941
  • ucp test image location: ghcr.io/radius-project/dev/ucpd:pr-func4dfb143941
  • deployment-engine test image location: ghcr.io/radius-project/deployment-engine:latest

Test Status

⌛ Building Radius and pushing container images for functional tests...
✅ Container images build succeeded
⌛ Publishing Bicep Recipes for functional tests...
✅ Recipe publishing succeeded
⌛ Starting corerp-cloud functional tests...
⌛ Starting ucp-cloud functional tests...
✅ ucp-cloud functional tests succeeded
✅ corerp-cloud functional tests succeeded

- Handle empty maps/arrays passed as strings in recipe parameters
- Add recursive normalization for nested structures with string-encoded empty objects
- Support whitespace variations (e.g., '{ }', '{}\n', '[ ]')
- Remove TF_LOG environment variable to prevent terraform-exec conflicts
- Add comprehensive test coverage for parameter normalization

Signed-off-by: ytimocin <[email protected]>
@ytimocin ytimocin force-pushed the ytimocin/air-gapped-cluster branch from f1615ee to 65e1f62 Compare July 22, 2025 06:40
Signed-off-by: ytimocin <[email protected]>
Test feature

Signed-off-by: Sylvain Niles <[email protected]>
@brooke-hamilton brooke-hamilton marked this pull request as ready for review July 23, 2025 18:07
@brooke-hamilton brooke-hamilton requested review from a team as code owners July 23, 2025 18:08
@brooke-hamilton brooke-hamilton marked this pull request as draft July 23, 2025 18:12
# Description

Bugfix and adds support for injecting azurerm credentials when provider
block is present.

## Type of change

<!--

Please select **one** of the following options that describes your
change and delete the others. Clearly identifying the type of change you
are making will help us review your PR faster, and is used in authoring
release notes.

If you are making a bug fix or functionality change to Radius and do not
have an associated issue link please create one now.

-->

- This pull request is a minor refactor, code cleanup, test improvement,
or other maintenance task and doesn't change the functionality of Radius
(issue link optional).


## Contributor checklist
Please verify that the PR meets the following requirements, where
applicable:

<!--
This checklist uses "TaskRadio" comments to make certain options
mutually exclusive.
See:
https://github.com/mheap/require-checklist-action?tab=readme-ov-file#radio-groups
For details on how this works and why it's required.
-->

- An overview of proposed schema changes is included in a linked GitHub
issue.
    - [ ] Yes <!-- TaskRadio schema -->
    - [x] Not applicable <!-- TaskRadio schema -->
- A design document PR is created in the [design-notes
repository](https://github.com/radius-project/design-notes/), if new
APIs are being introduced.
    - [ ] Yes <!-- TaskRadio design-pr -->
    - [x] Not applicable <!-- TaskRadio design-pr -->
- The design document has been reviewed and approved by Radius
maintainers/approvers.
    - [ ] Yes <!-- TaskRadio design-review -->
    - [x] Not applicable <!-- TaskRadio design-review -->
- A PR for the [samples
repository](https://github.com/radius-project/samples) is created, if
existing samples are affected by the changes in this PR.
    - [ ] Yes <!-- TaskRadio samples-pr -->
    - [x] Not applicable <!-- TaskRadio samples-pr -->
- A PR for the [documentation
repository](https://github.com/radius-project/docs) is created, if the
changes in this PR affect the documentation or any user facing updates
are made.
    - [ ] Yes <!-- TaskRadio docs-pr -->
    - [x] Not applicable <!-- TaskRadio docs-pr -->
- A PR for the [recipes
repository](https://github.com/radius-project/recipes) is created, if
existing recipes are affected by the changes in this PR.
    - [ ] Yes <!-- TaskRadio recipes-pr -->
    - [x] Not applicable <!-- TaskRadio recipes-pr -->

---------

Signed-off-by: Sylvain Niles <[email protected]>
# Description

Sets the OS environment variable for git binary to use the provided
cert.

## Type of change

<!--

Please select **one** of the following options that describes your
change and delete the others. Clearly identifying the type of change you
are making will help us review your PR faster, and is used in authoring
release notes.

If you are making a bug fix or functionality change to Radius and do not
have an associated issue link please create one now.

-->

- This pull request is a minor refactor, code cleanup, test improvement,
or other maintenance task and doesn't change the functionality of Radius
(issue link optional).

<!--

Please update the following to link the associated issue. This is
required for some kinds of changes (see above).

-->



## Contributor checklist
Please verify that the PR meets the following requirements, where
applicable:

<!--
This checklist uses "TaskRadio" comments to make certain options
mutually exclusive.
See:
https://github.com/mheap/require-checklist-action?tab=readme-ov-file#radio-groups
For details on how this works and why it's required.
-->

- An overview of proposed schema changes is included in a linked GitHub
issue.
    - [ ] Yes <!-- TaskRadio schema -->
    - [x] Not applicable <!-- TaskRadio schema -->
- A design document PR is created in the [design-notes
repository](https://github.com/radius-project/design-notes/), if new
APIs are being introduced.
    - [ ] Yes <!-- TaskRadio design-pr -->
    - [x] Not applicable <!-- TaskRadio design-pr -->
- The design document has been reviewed and approved by Radius
maintainers/approvers.
    - [ ] Yes <!-- TaskRadio design-review -->
    - [x] Not applicable <!-- TaskRadio design-review -->
- A PR for the [samples
repository](https://github.com/radius-project/samples) is created, if
existing samples are affected by the changes in this PR.
    - [ ] Yes <!-- TaskRadio samples-pr -->
    - [x] Not applicable <!-- TaskRadio samples-pr -->
- A PR for the [documentation
repository](https://github.com/radius-project/docs) is created, if the
changes in this PR affect the documentation or any user facing updates
are made.
    - [ ] Yes <!-- TaskRadio docs-pr -->
    - [x] Not applicable <!-- TaskRadio docs-pr -->
- A PR for the [recipes
repository](https://github.com/radius-project/recipes) is created, if
existing recipes are affected by the changes in this PR.
    - [ ] Yes <!-- TaskRadio recipes-pr -->
    - [x] Not applicable <!-- TaskRadio recipes-pr -->
Comment on lines +455 to +482
for _, f := range r.File {
fp := filepath.Join(destDir, f.Name)
if f.FileInfo().IsDir() {
if err := os.MkdirAll(fp, 0755); err != nil {
return err
}
continue
}
if err := os.MkdirAll(filepath.Dir(fp), 0755); err != nil {
return err
}
rc, err := f.Open()
if err != nil {
return err
}
out, err := os.OpenFile(fp, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, f.Mode())
if err != nil {
rc.Close()
return err
}
if _, err := io.Copy(out, rc); err != nil {
out.Close()
rc.Close()
return err
}
out.Close()
rc.Close()
}

Check failure

Code scanning / CodeQL

Arbitrary file access during archive extraction ("Zip Slip") High

Unsanitized archive entry, which may contain '..', is used in a
file system operation
.
Unsanitized archive entry, which may contain '..', is used in a
file system operation
.
Unsanitized archive entry, which may contain '..', is used in a
file system operation
.

Copilot Autofix

AI 2 months ago

To fix this issue, we must ensure that files extracted from zip entries are only written beneath the intended destDir and cannot escape via directory traversal (..) or absolute paths. The best way to do this is to construct the full output path for each entry, then check that its normalized (absolute) path remains under destDir. The easy way is to use filepath.Join(destDir, f.Name) to construct the target path, then resolve both destDir and the target path to their absolute forms (with filepath.Abs), and check that the target path starts with the destination directory’s path.

Additionally, we should reject absolute paths, or any entry with .. components in its name. We should skip any such entry, or fail the extraction.

You only need to edit the unzip function in pkg/recipes/driver/terraform/registry.go. To implement the fix:

  • Import path/filepath and use its Abs and Clean functions to compute absolute paths.
  • Before creating directories or files, validate the path:
    1. Get the absolute path of destDir and fp.
    2. Ensure the absolute path of the file starts with the absolute path to the output directory, with a path separator after the directory to avoid prefix issues.
    3. Optionally, skip entries whose names include .. or start with a separator (i.e., are absolute).
  • If the check fails, skip the entry or return an error.
  • No new dependencies are required.

Edits will be confined to the unzip function code block.


Suggested changeset 1
pkg/recipes/driver/terraform/registry.go

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/pkg/recipes/driver/terraform/registry.go b/pkg/recipes/driver/terraform/registry.go
--- a/pkg/recipes/driver/terraform/registry.go
+++ b/pkg/recipes/driver/terraform/registry.go
@@ -373,22 +373,37 @@
 		return err
 	}
 	defer r.Close()
+	absDestDir, err := filepath.Abs(destDir)
+	if err != nil {
+		return err
+	}
 	for _, f := range r.File {
-		fp := filepath.Join(destDir, f.Name)
+		// Prevent Zip Slip by cleaning and checking the filepath
+		fp := filepath.Join(absDestDir, f.Name)
+		fp = filepath.Clean(fp)
+		absFP, err := filepath.Abs(fp)
+		if err != nil {
+			return err
+		}
+		// The filepath must start with the destination directory + separator to prevent prefix matches
+		// Also ensure f.Name does not contain ".." or is absolute
+		if !strings.HasPrefix(absFP, absDestDir+string(os.PathSeparator)) && absFP != absDestDir {
+			return fmt.Errorf("illegal file path in zip: %s", f.Name)
+		}
 		if f.FileInfo().IsDir() {
-			if err := os.MkdirAll(fp, 0755); err != nil {
+			if err := os.MkdirAll(absFP, 0755); err != nil {
 				return err
 			}
 			continue
 		}
-		if err := os.MkdirAll(filepath.Dir(fp), 0755); err != nil {
+		if err := os.MkdirAll(filepath.Dir(absFP), 0755); err != nil {
 			return err
 		}
 		rc, err := f.Open()
 		if err != nil {
 			return err
 		}
-		out, err := os.OpenFile(fp, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, f.Mode())
+		out, err := os.OpenFile(absFP, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, f.Mode())
 		if err != nil {
 			rc.Close()
 			return err
EOF
@@ -373,22 +373,37 @@
return err
}
defer r.Close()
absDestDir, err := filepath.Abs(destDir)
if err != nil {
return err
}
for _, f := range r.File {
fp := filepath.Join(destDir, f.Name)
// Prevent Zip Slip by cleaning and checking the filepath
fp := filepath.Join(absDestDir, f.Name)
fp = filepath.Clean(fp)
absFP, err := filepath.Abs(fp)
if err != nil {
return err
}
// The filepath must start with the destination directory + separator to prevent prefix matches
// Also ensure f.Name does not contain ".." or is absolute
if !strings.HasPrefix(absFP, absDestDir+string(os.PathSeparator)) && absFP != absDestDir {
return fmt.Errorf("illegal file path in zip: %s", f.Name)
}
if f.FileInfo().IsDir() {
if err := os.MkdirAll(fp, 0755); err != nil {
if err := os.MkdirAll(absFP, 0755); err != nil {
return err
}
continue
}
if err := os.MkdirAll(filepath.Dir(fp), 0755); err != nil {
if err := os.MkdirAll(filepath.Dir(absFP), 0755); err != nil {
return err
}
rc, err := f.Open()
if err != nil {
return err
}
out, err := os.OpenFile(fp, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, f.Mode())
out, err := os.OpenFile(absFP, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, f.Mode())
if err != nil {
rc.Close()
return err
Copilot is powered by AI and may make mistakes. Always verify output.
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.

6 participants