mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-18 20:17:04 +00:00
* Merge commit from fork * fix: prevent unbounded read in Terraform remote configuration loader (GHSA-fmgp-q6jx-gg3x) * fix: bound remote Terraform clone and invalidate cache on rejection Follow-up hardening for GHSA-fmgp-q6jx-gg3x. Bound the clone of the attacker-supplied repository: shallow Depth:1, a 2-minute fetch timeout via PlainCloneContext, and post-clone caps on the retained tree size (64 MiB) and file count, rejecting and removing a clone that exceeds them. Invalidate the clone cache: re-clone when the recorded remote URL changes, and remove the cache on a failed clone or a rejected read so a corrected repository is re-fetched instead of a poisoned or stale tree being reused. Validate the module name before building the cache path, and log clone, rejection, and eviction events. Signed-off-by: Ayush Kumar <ayushshyamkumar888@gmail.com> * Fix: resolve gosec G304 lint failure in Terraform module cache check (#7190) Wrap the cache remote marker read in filepath.Clean, the same pattern other os.ReadFile call sites in this repo use to satisfy gosec. The path is built from filepath.Join and a constant suffix, with the module name validated beforehand, so behavior is unchanged. The finding surfaced on master after the GHSA-fmgp-q6jx-gg3x merge because the advisory workflow did not run the full lint job. Signed-off-by: Ayush Kumar <ayushshyamkumar888@gmail.com> * Fix: retain resource creator when rebuilding appliedResources from ResourceTracker The release-1.10 change that rebuilds Application status.appliedResources from the ResourceTracker (#7086) dropped the per-resource creator, because the ResourceTracker does not persist the creator field. As a result status.appliedResources reported an empty creator and the "applied resource in workflow step status" controller test failed, since it expects the creator "workflow". Re-attach the creator recorded during dispatch to the resources rebuilt from the ResourceTracker. The ResourceTracker stays authoritative for which resources exist; only the creator attribution that it does not persist is restored. Signed-off-by: Ayush Kumar <65535504+roguepikachu@users.noreply.github.com> * Fix: do not log or persist credentials embedded in Terraform module remote URLs The remote URL of a Terraform module can embed credentials (for example https://user:token@host/repo.git). The cache-reuse logic logged the raw URL and wrote it to the .remote-url cache marker, which could leak those credentials into controller logs and onto disk. Strip the userinfo from the URL before logging it and before writing the cache marker. The marker now stores a credential-free URL and the reuse check compares the same stripped form, so cache reuse and re-clone-on-change behave as before while no secret is persisted. Signed-off-by: Ayush Kumar <65535504+roguepikachu@users.noreply.github.com> --------- Signed-off-by: Ayush Kumar <ayushshyamkumar888@gmail.com> Signed-off-by: Ayush Kumar <65535504+roguepikachu@users.noreply.github.com>
134 lines
3.2 KiB
Go
134 lines
3.2 KiB
Go
/*
|
|
Copyright 2022 The KubeVela Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package utils
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestGetTerraformConfigurationFromRemote(t *testing.T) {
|
|
type want struct {
|
|
config string
|
|
errMsg string
|
|
}
|
|
|
|
type args struct {
|
|
name string
|
|
url string
|
|
path string
|
|
data []byte
|
|
variableFile string
|
|
}
|
|
cases := map[string]struct {
|
|
args args
|
|
want want
|
|
}{
|
|
"valid": {
|
|
args: args{
|
|
name: "valid",
|
|
url: "https://github.com/kubevela-contrib/terraform-modules.git",
|
|
path: "unittest/",
|
|
data: []byte(`
|
|
variable "aaa" {
|
|
type = list(object({
|
|
type = string
|
|
sourceArn = string
|
|
config = string
|
|
}))
|
|
default = []
|
|
}`),
|
|
variableFile: "main.tf",
|
|
},
|
|
want: want{
|
|
config: `
|
|
variable "aaa" {
|
|
type = list(object({
|
|
type = string
|
|
sourceArn = string
|
|
config = string
|
|
}))
|
|
default = []
|
|
}`,
|
|
},
|
|
},
|
|
"configuration is remote with path": {
|
|
args: args{
|
|
name: "aws-subnet",
|
|
url: "https://github.com/kubevela-contrib/terraform-modules.git",
|
|
path: "unittest/aws/subnet",
|
|
data: []byte(`
|
|
variable "aaa" {
|
|
type = list(object({
|
|
type = string
|
|
sourceArn = string
|
|
config = string
|
|
}))
|
|
default = []
|
|
}`),
|
|
variableFile: "variables.tf",
|
|
},
|
|
want: want{
|
|
config: `
|
|
variable "aaa" {
|
|
type = list(object({
|
|
type = string
|
|
sourceArn = string
|
|
config = string
|
|
}))
|
|
default = []
|
|
}`,
|
|
},
|
|
},
|
|
}
|
|
|
|
for name, tc := range cases {
|
|
t.Run(name, func(t *testing.T) {
|
|
home, _ := os.UserHomeDir()
|
|
path := filepath.Join(home, ".vela", "terraform")
|
|
cacheRoot := filepath.Join(path, tc.args.name)
|
|
tmpPath := filepath.Join(path, tc.args.name, tc.args.path)
|
|
if len(tc.args.data) > 0 {
|
|
err := os.MkdirAll(tmpPath, os.ModePerm)
|
|
assert.NoError(t, err)
|
|
err = os.WriteFile(filepath.Clean(filepath.Join(tmpPath, tc.args.variableFile)), tc.args.data, 0644)
|
|
assert.NoError(t, err)
|
|
// Record the remote URL so the populated cache is reused. URL-keyed
|
|
// reuse was added for GHSA-fmgp-q6jx-gg3x; without the marker the
|
|
// loader would treat the cache as stale and attempt a real clone.
|
|
err = os.WriteFile(cacheRoot+cacheRemoteMarkerSuffix, []byte(tc.args.url), 0600)
|
|
assert.NoError(t, err)
|
|
}
|
|
defer os.RemoveAll(cacheRoot)
|
|
defer os.Remove(cacheRoot + cacheRemoteMarkerSuffix)
|
|
|
|
conf, err := GetTerraformConfigurationFromRemote(tc.args.name, tc.args.url, tc.args.path, nil)
|
|
if tc.want.errMsg != "" {
|
|
if err != nil && !strings.Contains(err.Error(), tc.want.errMsg) {
|
|
t.Errorf("\n%s\nGetTerraformConfigurationFromRemote(...): -want error %v, +got error:%s", name, err, tc.want.errMsg)
|
|
}
|
|
} else {
|
|
assert.Equal(t, tc.want.config, conf)
|
|
}
|
|
})
|
|
}
|
|
}
|