Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added SSL support for deleting restic repository from Minio backend #464

Merged
merged 2 commits into from
May 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions hack/deploy/rbac-list.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ rules:
- customresourcedefinitions
verbs:
- "*"
- apiGroups:
Copy link
Member

Choose a reason for hiding this comment

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

@emruz-hossain , why do we need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added this rules to avoid this.

Log from operator:

I0505 15:10:48.997875       1 reflector.go:240] Listing and watching *v1beta1.MutatingWebhookConfiguration from github.com/appscode/stash/vendor/k8s.io/client-go/informers/factory.go:87
I0505 15:10:49.000133       1 reflector.go:240] Listing and watching *v1beta1.ValidatingWebhookConfiguration from github.com/appscode/stash/vendor/k8s.io/client-go/informers/factory.go:87
E0505 15:10:49.001929       1 reflector.go:205] github.com/appscode/stash/vendor/k8s.io/client-go/informers/factory.go:87: Failed to list *v1beta1.MutatingWebhookConfiguration: mutatingwebhookconfigurations.admissionregistration.k8s.io is forbidden: User "system:serviceaccount:kube-system:stash-operator" cannot list mutatingwebhookconfigurations.admissionregistration.k8s.io at the cluster scope
E0505 15:10:49.004334       1 reflector.go:205] github.com/appscode/stash/vendor/k8s.io/client-go/informers/factory.go:87: Failed to list *v1beta1.ValidatingWebhookConfiguration: validatingwebhookconfigurations.admissionregistration.k8s.io is forbidden: User "system:serviceaccount:kube-system:stash-operator" cannot list validatingwebhookconfigurations.admissionregistration.k8s.io at the cluster scope
I0505 15:10:50.002391       1 reflector.go:240] Listing and watching *v1beta1.MutatingWebhookConfiguration from github.com/appscode/stash/vendor/k8s.io/client-go/informers/factory.go:87

I haven't notice them before. We don't watch webhookconfiguration in operator. But I don't know why operator is watching those. This seems to happen after client-go update.

However, after adding those rules still see this in log,

I0505 15:23:43.179154       1 reflector.go:240] Listing and watching *v1beta1.ValidatingWebhookConfiguration from github.com/appscode/stash/vendor/k8s.io/client-go/informers/factory.go:87
I0505 15:23:43.179154       1 reflector.go:240] Listing and watching *v1beta1.MutatingWebhookConfiguration from github.com/appscode/stash/vendor/k8s.io/client-go/informers/factory.go:87
E0505 15:23:43.188256       1 reflector.go:322] github.com/appscode/stash/vendor/k8s.io/client-go/informers/factory.go:87: Failed to watch *v1beta1.MutatingWebhookConfiguration: unknown (get mutatingwebhookconfigurations.admissionregistration.k8s.io)
E0505 15:23:43.189344       1 reflector.go:322] github.com/appscode/stash/vendor/k8s.io/client-go/informers/factory.go:87: Failed to watch *v1beta1.ValidatingWebhookConfiguration: unknown (get validatingwebhookconfigurations.admissionregistration.k8s.io)

Btw, these does not seem to cause any problems for operator's regular task.

Copy link
Member

Choose a reason for hiding this comment

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

I haven't notice them before. We don't watch webhookconfiguration in operator. But I don't know why operator is watching those. This seems to happen after client-go update.

You are right. I also noticed a line like plugins.go:149] Loaded 3 admission controller(s) successfully in the following order: NamespaceLifecycle,MutatingAdmissionWebhook,ValidatingAdmissionWebhook.

I think the proper fix is disabling admission plugins for webhook server. openshift/generic-admission-server#14

- admissionregistration.k8s.io
resources:
- mutatingwebhookconfigurations
- validatingwebhookconfigurations
verbs: ["get","list"]
- apiGroups:
- extensions
resources:
Expand Down
7 changes: 6 additions & 1 deletion pkg/controller/rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,14 @@ func (c *StashController) ensureSidecarClusterRole() error {
},
{
APIGroups: []string{core.GroupName},
Resources: []string{"replicationcontrollers", "secrets"},
Resources: []string{"replicationcontrollers"},
Verbs: []string{"get", "list", "patch"},
},
{
APIGroups: []string{core.GroupName},
Resources: []string{"secrets"},
Verbs: []string{"get"},
},
{
APIGroups: []string{core.GroupName},
Resources: []string{"configmaps"},
Expand Down
29 changes: 27 additions & 2 deletions pkg/osm/osm.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package osm

import (
"io/ioutil"
"net/url"
"os"
"path/filepath"
"strconv"
"strings"

Expand All @@ -25,6 +28,12 @@ import (
"k8s.io/client-go/kubernetes"
)

const (
CA_CERT_DATA = "CA_CERT_DATA"
CaCertMountPath = "/tmp/osm"
CaCertFileName = "ca.crt"
)

func NewOSMContext(client kubernetes.Interface, repository *api.Repository) (*otx.Context, error) {
config := make(map[string][]byte)

Expand Down Expand Up @@ -86,8 +95,24 @@ func NewOSMContext(client kubernetes.Interface, repository *api.Repository) (*ot
nc.Config[s3.ConfigRegion] = stringz.Val(types.String(out.LocationConstraint), "us-east-1")
} else {
nc.Config[s3.ConfigEndpoint] = repository.Spec.Backend.S3.Endpoint
if u, err := url.Parse(repository.Spec.Backend.S3.Endpoint); err == nil {
nc.Config[s3.ConfigDisableSSL] = strconv.FormatBool(u.Scheme == "http")
u, err := url.Parse(repository.Spec.Backend.S3.Endpoint)
if err != nil {
return nil, err
}
nc.Config[s3.ConfigDisableSSL] = strconv.FormatBool(u.Scheme == "http")

cacertData, ok := config[CA_CERT_DATA]
if ok && u.Scheme == "https" {
certFileName := filepath.Join(CaCertMountPath, CaCertFileName)
err = os.MkdirAll(filepath.Dir(certFileName), 0755)
if err != nil {
return nil, err
}
err = ioutil.WriteFile(certFileName, cacertData, 0755)
if err != nil {
return nil, err
}
nc.Config[s3.ConfigCACertFile] = certFileName
}
}
return nc, nil
Expand Down
15 changes: 8 additions & 7 deletions test/e2e/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package e2e_test

import (
"io/ioutil"
"net"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -787,7 +788,7 @@ var _ = Describe("Deployment", func() {
Context("With cacert", func() {
BeforeEach(func() {
By("Creating Minio server with cacert")
addrs, err := f.CreateMinioServer(true)
addrs, err := f.CreateMinioServer(true, nil)
Expect(err).NotTo(HaveOccurred())

restic = f.ResticForMinioBackend("https://" + addrs)
Expand Down Expand Up @@ -828,7 +829,7 @@ var _ = Describe("Deployment", func() {
Context("Without cacert", func() {
BeforeEach(func() {
By("Creating Minio server with cacert")
addrs, err := f.CreateMinioServer(true)
addrs, err := f.CreateMinioServer(true, nil)
Expect(err).NotTo(HaveOccurred())

restic = f.ResticForMinioBackend("https://" + addrs)
Expand Down Expand Up @@ -1326,18 +1327,18 @@ var _ = Describe("Deployment", func() {
f.DeleteMinioServer()
})
BeforeEach(func() {
minikubeIP := net.IP{192, 168, 99, 100}

By("Creating Minio server without cacert")
_, err = f.CreateMinioServer(false)
By("Creating Minio server with cacert")
_, err = f.CreateMinioServer(true, []net.IP{minikubeIP})
Expect(err).NotTo(HaveOccurred())

minikubeIP := "192.168.99.100"
msvc, err := f.KubeClient.CoreV1().Services(f.Namespace()).Get("minio-service", metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())
minioServiceNodePort := strconv.Itoa(int(msvc.Spec.Ports[0].NodePort))

restic = f.ResticForMinioBackend("http://" + minikubeIP + ":" + minioServiceNodePort)
cred = f.SecretForMinioBackend(false)
restic = f.ResticForMinioBackend("https://" + minikubeIP.String() + ":" + minioServiceNodePort)
cred = f.SecretForMinioBackend(true)
})
It(`should delete repository from minio backend`, func() {
shouldBackupNewDeployment()
Expand Down
78 changes: 67 additions & 11 deletions test/e2e/framework/minio_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package framework

import (
"fmt"
"net"
"path/filepath"
"time"

"github.com/appscode/go/crypto/rand"
"github.com/appscode/go/types"
core_util "github.com/appscode/kutil/core/v1"
. "github.com/onsi/gomega"
apps "k8s.io/api/apps/v1beta1"
Expand All @@ -17,10 +20,13 @@ import (

const (
MINIO_PUBLIC_CRT_NAME = "public.crt"
MINIO_PRIVSTE_KEY_NAME = "private.key"
MINIO_PRIVATE_KEY_NAME = "private.key"

MINIO_ACCESS_KEY_ID = "not@id"
MINIO_SECRET_ACCESS_KEY = "not@secret"

MINIO_CERTS_MOUNTPATH = "/root/.minio/certs"
StandardStorageClass = "standard"
)

var (
Expand All @@ -30,9 +36,9 @@ var (
msrvc core.Service
)

func (fi *Invocation) CreateMinioServer(tls bool) (string, error) {
func (fi *Invocation) CreateMinioServer(tls bool, ips []net.IP) (string, error) {
//creating secret for minio server
mcred = fi.SecretForMinioServer()
mcred = fi.SecretForMinioServer(ips)
err := fi.CreateSecret(mcred)
if err != nil {
return "", err
Expand Down Expand Up @@ -65,8 +71,8 @@ func (fi *Invocation) CreateMinioServer(tls bool) (string, error) {
return fi.MinioServiceAddres(), nil
}

func (fi *Invocation) SecretForMinioServer() core.Secret {
crt, key, err := fi.CertStore.NewServerCertPair("server", fi.MinioServerSANs())
func (fi *Invocation) SecretForMinioServer(ips []net.IP) core.Secret {
crt, key, err := fi.CertStore.NewServerCertPair("server", fi.MinioServerSANs(ips))
Expect(err).NotTo(HaveOccurred())

return core.Secret{
Expand All @@ -76,7 +82,7 @@ func (fi *Invocation) SecretForMinioServer() core.Secret {
},
Data: map[string][]byte{
MINIO_PUBLIC_CRT_NAME: []byte(string(crt) + "\n" + string(fi.CertStore.CACert())),
MINIO_PRIVSTE_KEY_NAME: key,
MINIO_PRIVATE_KEY_NAME: key,
},
}
}
Expand All @@ -100,6 +106,7 @@ func (fi *Invocation) PVCForMinioServer() core.PersistentVolumeClaim {
core.ResourceName(core.ResourceStorage): resource.MustParse("2Gi"),
},
},
StorageClassName: types.StringP(StandardStorageClass),
},
}
}
Expand Down Expand Up @@ -138,10 +145,44 @@ func (fi *Invocation) DeploymentForMinioServer() apps.Deployment {
},
},
{
Name: "minio-secret",
Name: "minio-public-crt",
VolumeSource: core.VolumeSource{
Secret: &core.SecretVolumeSource{
SecretName: "minio-server-secret",
Items: []core.KeyToPath{
{
Key: MINIO_PUBLIC_CRT_NAME,
Path: MINIO_PUBLIC_CRT_NAME,
},
},
},
},
},
{
Name: "minio-private-key",
VolumeSource: core.VolumeSource{
Secret: &core.SecretVolumeSource{
SecretName: "minio-server-secret",
Items: []core.KeyToPath{
{
Key: MINIO_PRIVATE_KEY_NAME,
Path: MINIO_PRIVATE_KEY_NAME,
},
},
},
},
},
{
Name: "minio-ca-crt",
VolumeSource: core.VolumeSource{
Secret: &core.SecretVolumeSource{
SecretName: "minio-server-secret",
Items: []core.KeyToPath{
{
Key: MINIO_PUBLIC_CRT_NAME,
Path: MINIO_PUBLIC_CRT_NAME,
},
},
},
},
},
Expand Down Expand Up @@ -179,8 +220,19 @@ func (fi *Invocation) DeploymentForMinioServer() apps.Deployment {
MountPath: "/storage",
},
{
Name: "minio-secret",
MountPath: "/root/.minio/certs/",
Name: "minio-public-crt",
MountPath: filepath.Join(MINIO_CERTS_MOUNTPATH, MINIO_PUBLIC_CRT_NAME),
SubPath: MINIO_PUBLIC_CRT_NAME,
},
{
Name: "minio-private-key",
MountPath: filepath.Join(MINIO_CERTS_MOUNTPATH, MINIO_PRIVATE_KEY_NAME),
SubPath: MINIO_PRIVATE_KEY_NAME,
},
{
Name: "minio-ca-crt",
MountPath: filepath.Join(MINIO_CERTS_MOUNTPATH, "CAs", MINIO_PUBLIC_CRT_NAME),
SubPath: MINIO_PUBLIC_CRT_NAME,
},
},
},
Expand Down Expand Up @@ -259,10 +311,14 @@ func (f *Framework) DeleteServiceForMinioServer(meta metav1.ObjectMeta) error {
return f.KubeClient.CoreV1().Services(meta.Namespace).Delete(meta.Name, deleteInForeground())
}

func (fi *Invocation) MinioServerSANs() cert.AltNames {
return cert.AltNames{
func (fi *Invocation) MinioServerSANs(ips []net.IP) cert.AltNames {
altNames := cert.AltNames{
DNSNames: []string{fi.MinioServiceAddres()},
}
if ips != nil {
altNames.IPs = ips
}
return altNames
}

func (fi *Invocation) MinioServiceAddres() string {
Expand Down
10 changes: 6 additions & 4 deletions test/e2e/snapshots_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package e2e_test

import (
"net"
"os"
"os/exec"
"strconv"
Expand Down Expand Up @@ -268,17 +269,18 @@ var _ = Describe("Snapshots", func() {
Skip("restic executable not found in /bin directory. Please install in /bin directory from: https://github.com/restic/restic/releases")
}

minikubeIP := net.IP{192, 168, 99, 100}

By("Creating Minio server without cacert")
_, err = f.CreateMinioServer(false)
_, err = f.CreateMinioServer(true, []net.IP{minikubeIP})
Expect(err).NotTo(HaveOccurred())

minikubeIP := "192.168.99.100"
msvc, err := f.KubeClient.CoreV1().Services(f.Namespace()).Get("minio-service", metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())
minioServiceNodePort := strconv.Itoa(int(msvc.Spec.Ports[0].NodePort))

restic = f.ResticForMinioBackend("http://" + minikubeIP + ":" + minioServiceNodePort)
cred = f.SecretForMinioBackend(false)
restic = f.ResticForMinioBackend("https://" + minikubeIP.String() + ":" + minioServiceNodePort)
cred = f.SecretForMinioBackend(true)
})
It(`should success to perform Snapshot's operations`, performOperationOnSnapshot)

Expand Down
Loading