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

[cherry-pick] Use BasicAuth Keys for reading credentials from secret (#543) #545

Merged
merged 1 commit into from
Jan 16, 2021
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
4 changes: 1 addition & 3 deletions Dockerfile.dbg
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ LABEL org.opencontainers.image.source https://github.com/stashed/elasticsearch
RUN set -x \
&& apk add --update --no-cache bash ca-certificates curl

# https://stackoverflow.com/a/52196681
RUN npm config set unsafe-perm true \
&& npm install elasticdump@4.1.2 -g
RUN npm install elasticdump@6.62.1 -g

COPY --from=0 restic /bin/restic
COPY bin/{ARG_OS}_{ARG_ARCH}/{ARG_BIN} /{ARG_BIN}
Expand Down
4 changes: 1 addition & 3 deletions Dockerfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ LABEL org.opencontainers.image.source https://github.com/stashed/elasticsearch
RUN set -x \
&& apk add --update --no-cache bash ca-certificates curl

# https://stackoverflow.com/a/52196681
RUN npm config set unsafe-perm true \
&& npm install elasticdump@4.1.2 -g
RUN npm install elasticdump@6.62.1 -g

COPY --from=0 /restic /bin/restic
COPY bin/{ARG_OS}_{ARG_ARCH}/{ARG_BIN} /{ARG_BIN}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/spf13/cobra v1.1.1
go.bytebuilders.dev/license-verifier/kubernetes v0.5.1
gomodules.xyz/x v0.0.0-20201105065653-91c568df6331
k8s.io/api v0.18.9
k8s.io/apimachinery v0.18.9
k8s.io/client-go v0.18.9
kmodules.xyz/client-go v0.0.0-20210108092221-c3812eb92bd0
Expand Down
10 changes: 9 additions & 1 deletion pkg/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ import (
license "go.bytebuilders.dev/license-verifier/kubernetes"
"gomodules.xyz/x/flags"
"gomodules.xyz/x/log"
core "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
meta_util "kmodules.xyz/client-go/meta"
appcatalog "kmodules.xyz/custom-resources/apis/appcatalog/v1alpha1"
appcatalog_cs "kmodules.xyz/custom-resources/client/clientset/versioned"
v1 "kmodules.xyz/offshoot-api/api/v1"
Expand Down Expand Up @@ -215,7 +217,13 @@ func (opt *esOptions) backupElasticsearch(targetRef api_v1beta1.TargetRef) (*res
}

appSVC := appBinding.Spec.ClientConfig.Service
esURL := fmt.Sprintf("%v://%s:%s@%s:%d", appSVC.Scheme, appBindingSecret.Data[ESUser], appBindingSecret.Data[ESPassword], appSVC.Name, appSVC.Port) // TODO: authplugin: none
esURL := fmt.Sprintf("%v://%s:%s@%s:%d",
appSVC.Scheme,
must(meta_util.GetBytesForKeys(appBindingSecret.Data, core.BasicAuthUsernameKey, ESUser)),
must(meta_util.GetBytesForKeys(appBindingSecret.Data, core.BasicAuthPasswordKey, ESPassword)),
appSVC.Name,
appSVC.Port,
) // TODO: support backup without authentication

// wait for DB ready
waitForDBReady(appBinding.Spec.ClientConfig.Service.Name, appBinding.Spec.ClientConfig.Service.Port, opt.waitTimeout)
Expand Down
10 changes: 9 additions & 1 deletion pkg/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ import (
license "go.bytebuilders.dev/license-verifier/kubernetes"
"gomodules.xyz/x/flags"
"gomodules.xyz/x/log"
core "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
meta_util "kmodules.xyz/client-go/meta"
appcatalog "kmodules.xyz/custom-resources/apis/appcatalog/v1alpha1"
appcatalog_cs "kmodules.xyz/custom-resources/client/clientset/versioned"
v1 "kmodules.xyz/offshoot-api/api/v1"
Expand Down Expand Up @@ -182,7 +184,13 @@ func (opt *esOptions) restoreElasticsearch(targetRef api_v1beta1.TargetRef) (*re
}

appSVC := appBinding.Spec.ClientConfig.Service
esURL := fmt.Sprintf("%v://%s:%s@%s:%d", appSVC.Scheme, appBindingSecret.Data[ESUser], appBindingSecret.Data[ESPassword], appSVC.Name, appSVC.Port) // TODO: support for authplugin: none
esURL := fmt.Sprintf("%v://%s:%s@%s:%d",
appSVC.Scheme,
must(meta_util.GetBytesForKeys(appBindingSecret.Data, core.BasicAuthUsernameKey, ESUser)),
must(meta_util.GetBytesForKeys(appBindingSecret.Data, core.BasicAuthPasswordKey, ESPassword)),
appSVC.Name,
appSVC.Port,
) // TODO: support backup without authentication

// wait for DB ready
waitForDBReady(appBinding.Spec.ClientConfig.Service.Name, appBinding.Spec.ClientConfig.Service.Port, opt.waitTimeout)
Expand Down
7 changes: 7 additions & 0 deletions pkg/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,10 @@ func clearDir(dir string) error {
}
return os.MkdirAll(dir, os.ModePerm)
}

func must(v []byte, err error) string {
if err != nil {
panic(err)
}
return string(v)
}