Skip to content

Commit

Permalink
Backport Helm security patch
Browse files Browse the repository at this point in the history
Signed-off-by: Hidde Beydals <hello@hidde.co>
  • Loading branch information
hiddeco committed Jul 15, 2021
1 parent 416392b commit e9b371b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 31 deletions.
17 changes: 4 additions & 13 deletions controllers/gitrepository_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"testing"
"time"

"github.com/fluxcd/pkg/testserver"
"github.com/go-git/go-billy/v5/memfs"
gogit "github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/config"
Expand All @@ -40,7 +39,6 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/utils/pointer"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -52,6 +50,7 @@ import (
"github.com/fluxcd/pkg/gittestserver"
"github.com/fluxcd/pkg/runtime/conditions"
"github.com/fluxcd/pkg/ssh"
"github.com/fluxcd/pkg/testserver"

sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
"github.com/fluxcd/source-controller/pkg/git"
Expand Down Expand Up @@ -316,9 +315,6 @@ func TestGitRepositoryReconciler_reconcileSource_authStrategy(t *testing.T) {
},
}

s := runtime.NewScheme()
utilruntime.Must(corev1.AddToScheme(s))

t.Run(tt.name, func(t *testing.T) {
g := NewWithT(t)

Expand Down Expand Up @@ -371,7 +367,7 @@ func TestGitRepositoryReconciler_reconcileSource_authStrategy(t *testing.T) {
tt.beforeFunc(obj)
}

builder := fakeclient.NewClientBuilder().WithScheme(s)
builder := fakeclient.NewClientBuilder().WithScheme(env.GetScheme())
if secret != nil {
builder.WithObjects(secret.DeepCopy())
}
Expand Down Expand Up @@ -805,9 +801,7 @@ func TestGitRepositoryReconciler_reconcileInclude(t *testing.T) {
depObjs = append(depObjs, obj)
}

s := runtime.NewScheme()
utilruntime.Must(sourcev1.AddToScheme(s))
builder := fakeclient.NewClientBuilder().WithScheme(s)
builder := fakeclient.NewClientBuilder().WithScheme(env.GetScheme())
if len(tt.dependencies) > 0 {
builder.WithObjects(depObjs...)
}
Expand Down Expand Up @@ -988,10 +982,7 @@ func TestGitRepositoryReconciler_verifyCommitSignature(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
g := NewWithT(t)

s := runtime.NewScheme()
utilruntime.Must(corev1.AddToScheme(s))

builder := fakeclient.NewClientBuilder().WithScheme(s)
builder := fakeclient.NewClientBuilder().WithScheme(env.GetScheme())
if tt.secret != nil {
builder.WithObjects(tt.secret)
}
Expand Down
2 changes: 2 additions & 0 deletions controllers/helmchart_controller_chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ func (r *HelmChartReconciler) getRepositoryIndex(ctx context.Context, obj *sourc
// Configure Helm client getter options
clientOpts := []getter.Option{
getter.WithTimeout(obj.Spec.Interval.Duration),
getter.WithURL(repository.Spec.URL),
getter.WithPassCredentialsAll(repository.Spec.PassCredentials),
}
if repository.Spec.SecretRef != nil {
name := types.NamespacedName{
Expand Down
2 changes: 2 additions & 0 deletions controllers/helmchart_controller_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ func (r *HelmChartReconciler) reconcileFromHelmRepository(ctx context.Context, o
// Configure Helm client to access repository
clientOpts := []getter.Option{
getter.WithTimeout(repository.Spec.Timeout.Duration),
getter.WithURL(repository.Spec.URL),
getter.WithPassCredentialsAll(repository.Spec.PassCredentials),
}
if repository.Spec.SecretRef != nil {
// Attempt to retrieve secret
Expand Down
22 changes: 4 additions & 18 deletions controllers/helmchart_controller_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import (
"helm.sh/helm/v3/pkg/chart/loader"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
ctrl "sigs.k8s.io/controller-runtime"
fakeclient "sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/controller-runtime/pkg/log"
Expand Down Expand Up @@ -152,10 +150,7 @@ func TestHelmChartReconciler_reconcileFromHelmRepository(t *testing.T) {
},
}

s := runtime.NewScheme()
utilruntime.Must(sourcev1.AddToScheme(s))

builder := fakeclient.NewClientBuilder().WithScheme(s)
builder := fakeclient.NewClientBuilder().WithScheme(env.GetScheme())
builder.WithObjects(sourceObj)

r := &HelmChartReconciler{
Expand Down Expand Up @@ -371,10 +366,7 @@ func TestHelmChartReconciler_reconcileFromHelmRepository_secretRef(t *testing.T)
tt.beforeFunc(repository)
}

s := runtime.NewScheme()
utilruntime.Must(corev1.AddToScheme(s))

builder := fakeclient.NewClientBuilder().WithScheme(s)
builder := fakeclient.NewClientBuilder().WithScheme(env.GetScheme())
secret := tt.secret.DeepCopy()
if secret != nil {
builder.WithObjects(secret.DeepCopy())
Expand Down Expand Up @@ -460,10 +452,7 @@ func TestHelmChartReconciler_reconcileFromTarballArtifact(t *testing.T) {
},
}

s := runtime.NewScheme()
utilruntime.Must(sourcev1.AddToScheme(s))

builder := fakeclient.NewClientBuilder().WithScheme(s)
builder := fakeclient.NewClientBuilder().WithScheme(env.GetScheme())

r := &HelmChartReconciler{
Client: builder.Build(),
Expand Down Expand Up @@ -576,10 +565,7 @@ func TestHelmChartReconciler_getSource(t *testing.T) {
},
}

s := runtime.NewScheme()
utilruntime.Must(sourcev1.AddToScheme(s))

builder := fakeclient.NewClientBuilder().WithScheme(s)
builder := fakeclient.NewClientBuilder().WithScheme(env.GetScheme())
builder.WithObjects(helmRepo, gitRepo, bucket)

r := &HelmChartReconciler{
Expand Down
2 changes: 2 additions & 0 deletions controllers/helmrepository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ func (r *HelmRepositoryReconciler) reconcileSource(ctx context.Context, obj *sou
// Configure Helm client to access repository
clientOpts := []getter.Option{
getter.WithTimeout(obj.Spec.Timeout.Duration),
getter.WithURL(obj.Spec.URL),
getter.WithPassCredentialsAll(obj.Spec.PassCredentials),
}
if obj.Spec.SecretRef != nil {
// Attempt to retrieve secret
Expand Down

0 comments on commit e9b371b

Please sign in to comment.