mirror of https://github.com/harness/drone.git
[AH-310]: temp push; need to check (#2607)
* [AH-310]: Updated secret flows * [AH-310]: Fixed build issues * [AH-310]: temp push; need to checkpull/3545/head
parent
57368eba55
commit
77e93d587c
|
@ -0,0 +1,62 @@
|
||||||
|
// Copyright 2023 Harness, Inc.
|
||||||
|
//
|
||||||
|
// 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 secret
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
secretCtrl "github.com/harness/gitness/app/api/controller/secret"
|
||||||
|
"github.com/harness/gitness/app/store"
|
||||||
|
"github.com/harness/gitness/encrypt"
|
||||||
|
"github.com/harness/gitness/secret"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
type service struct {
|
||||||
|
secretStore store.SecretStore
|
||||||
|
encrypter encrypt.Encrypter
|
||||||
|
spacePathStore store.SpacePathStore
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewService(
|
||||||
|
secretStore store.SecretStore, encrypter encrypt.Encrypter, spacePathStore store.SpacePathStore,
|
||||||
|
) secret.Service {
|
||||||
|
return &service{
|
||||||
|
secretStore: secretStore,
|
||||||
|
encrypter: encrypter,
|
||||||
|
spacePathStore: spacePathStore,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *service) DecryptSecret(ctx context.Context, spacePath string, secretIdentifier string) (string, error) {
|
||||||
|
path, err := s.spacePathStore.FindByPath(ctx, spacePath)
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Msgf("failed to find space path: %v", err)
|
||||||
|
return "", errors.Wrap(err, "failed to find space path")
|
||||||
|
}
|
||||||
|
sec, err := s.secretStore.FindByIdentifier(ctx, path.SpaceID, secretIdentifier)
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Msgf("failed to find secret: %v", err)
|
||||||
|
return "", errors.Wrap(err, "failed to find secret")
|
||||||
|
}
|
||||||
|
sec, err = secretCtrl.Dec(s.encrypter, sec)
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Msgf("could not decrypt secret: %v", err)
|
||||||
|
return "", errors.Wrap(err, "failed to decrypt secret")
|
||||||
|
}
|
||||||
|
return sec.Data, nil
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
// Copyright 2023 Harness, Inc.
|
||||||
|
//
|
||||||
|
// 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 secret
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/harness/gitness/app/store"
|
||||||
|
"github.com/harness/gitness/encrypt"
|
||||||
|
"github.com/harness/gitness/secret"
|
||||||
|
|
||||||
|
"github.com/google/wire"
|
||||||
|
)
|
||||||
|
|
||||||
|
var WireSet = wire.NewSet(
|
||||||
|
ProvideSecretService,
|
||||||
|
)
|
||||||
|
|
||||||
|
func ProvideSecretService(
|
||||||
|
secretStore store.SecretStore, encrypter encrypt.Encrypter, spacePathStore store.SpacePathStore,
|
||||||
|
) secret.Service {
|
||||||
|
return NewService(secretStore, encrypter, spacePathStore)
|
||||||
|
}
|
|
@ -100,6 +100,7 @@ import (
|
||||||
"github.com/harness/gitness/app/services/publickey"
|
"github.com/harness/gitness/app/services/publickey"
|
||||||
pullreqservice "github.com/harness/gitness/app/services/pullreq"
|
pullreqservice "github.com/harness/gitness/app/services/pullreq"
|
||||||
reposervice "github.com/harness/gitness/app/services/repo"
|
reposervice "github.com/harness/gitness/app/services/repo"
|
||||||
|
secretservice "github.com/harness/gitness/app/services/secret"
|
||||||
"github.com/harness/gitness/app/services/settings"
|
"github.com/harness/gitness/app/services/settings"
|
||||||
"github.com/harness/gitness/app/services/trigger"
|
"github.com/harness/gitness/app/services/trigger"
|
||||||
usergroupservice "github.com/harness/gitness/app/services/usergroup"
|
usergroupservice "github.com/harness/gitness/app/services/usergroup"
|
||||||
|
@ -262,6 +263,7 @@ func initSystem(ctx context.Context, config *types.Config) (*cliserver.System, e
|
||||||
aiagent.WireSet,
|
aiagent.WireSet,
|
||||||
capabilities.WireSet,
|
capabilities.WireSet,
|
||||||
capabilitiesservice.WireSet,
|
capabilitiesservice.WireSet,
|
||||||
|
secretservice.WireSet,
|
||||||
)
|
)
|
||||||
return &cliserver.System{}, nil
|
return &cliserver.System{}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,6 +91,7 @@ import (
|
||||||
"github.com/harness/gitness/app/services/publickey"
|
"github.com/harness/gitness/app/services/publickey"
|
||||||
"github.com/harness/gitness/app/services/pullreq"
|
"github.com/harness/gitness/app/services/pullreq"
|
||||||
repo2 "github.com/harness/gitness/app/services/repo"
|
repo2 "github.com/harness/gitness/app/services/repo"
|
||||||
|
secret3 "github.com/harness/gitness/app/services/secret"
|
||||||
"github.com/harness/gitness/app/services/settings"
|
"github.com/harness/gitness/app/services/settings"
|
||||||
trigger2 "github.com/harness/gitness/app/services/trigger"
|
trigger2 "github.com/harness/gitness/app/services/trigger"
|
||||||
"github.com/harness/gitness/app/services/usergroup"
|
"github.com/harness/gitness/app/services/usergroup"
|
||||||
|
@ -429,7 +430,8 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro
|
||||||
registryBlobRepository := database2.ProvideRegistryBlobDao(db)
|
registryBlobRepository := database2.ProvideRegistryBlobDao(db)
|
||||||
localRegistry := docker.LocalRegistryProvider(app, manifestService, blobRepository, registryRepository, manifestRepository, registryBlobRepository, mediaTypesRepository, tagRepository, artifactRepository, artifactStatRepository, gcService, transactor)
|
localRegistry := docker.LocalRegistryProvider(app, manifestService, blobRepository, registryRepository, manifestRepository, registryBlobRepository, mediaTypesRepository, tagRepository, artifactRepository, artifactStatRepository, gcService, transactor)
|
||||||
upstreamProxyConfigRepository := database2.ProvideUpstreamDao(db, registryRepository)
|
upstreamProxyConfigRepository := database2.ProvideUpstreamDao(db, registryRepository)
|
||||||
remoteRegistry := docker.RemoteRegistryProvider(localRegistry, app, upstreamProxyConfigRepository, secretStore, encrypter)
|
secretService := secret3.ProvideSecretService(secretStore, encrypter, spacePathStore)
|
||||||
|
remoteRegistry := docker.RemoteRegistryProvider(localRegistry, app, upstreamProxyConfigRepository, spacePathStore, secretService)
|
||||||
coreController := pkg.CoreControllerProvider(registryRepository)
|
coreController := pkg.CoreControllerProvider(registryRepository)
|
||||||
dockerController := docker.ControllerProvider(localRegistry, remoteRegistry, coreController, spaceStore, authorizer)
|
dockerController := docker.ControllerProvider(localRegistry, remoteRegistry, coreController, spaceStore, authorizer)
|
||||||
handler := api2.NewHandlerProvider(dockerController, spaceStore, tokenStore, controller, authenticator, provider, authorizer)
|
handler := api2.NewHandlerProvider(dockerController, spaceStore, tokenStore, controller, authenticator, provider, authorizer)
|
||||||
|
|
|
@ -25,7 +25,6 @@ import (
|
||||||
|
|
||||||
"github.com/harness/gitness/app/api/request"
|
"github.com/harness/gitness/app/api/request"
|
||||||
store2 "github.com/harness/gitness/app/store"
|
store2 "github.com/harness/gitness/app/store"
|
||||||
"github.com/harness/gitness/encrypt"
|
|
||||||
"github.com/harness/gitness/registry/app/common/lib/errors"
|
"github.com/harness/gitness/registry/app/common/lib/errors"
|
||||||
"github.com/harness/gitness/registry/app/manifest"
|
"github.com/harness/gitness/registry/app/manifest"
|
||||||
"github.com/harness/gitness/registry/app/pkg"
|
"github.com/harness/gitness/registry/app/pkg"
|
||||||
|
@ -33,6 +32,7 @@ import (
|
||||||
proxy2 "github.com/harness/gitness/registry/app/remote/controller/proxy"
|
proxy2 "github.com/harness/gitness/registry/app/remote/controller/proxy"
|
||||||
"github.com/harness/gitness/registry/app/storage"
|
"github.com/harness/gitness/registry/app/storage"
|
||||||
"github.com/harness/gitness/registry/app/store"
|
"github.com/harness/gitness/registry/app/store"
|
||||||
|
"github.com/harness/gitness/secret"
|
||||||
|
|
||||||
v1 "github.com/opencontainers/image-spec/specs-go/v1"
|
v1 "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
@ -48,18 +48,15 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewRemoteRegistry(
|
func NewRemoteRegistry(
|
||||||
local *LocalRegistry,
|
local *LocalRegistry, app *App, upstreamProxyConfigRepo store.UpstreamProxyConfigRepository,
|
||||||
app *App,
|
spacePathStore store2.SpacePathStore, secretService secret.Service,
|
||||||
upstreamProxyConfigRepo store.UpstreamProxyConfigRepository,
|
|
||||||
secretStore store2.SecretStore,
|
|
||||||
encrypter encrypt.Encrypter,
|
|
||||||
) Registry {
|
) Registry {
|
||||||
return &RemoteRegistry{
|
return &RemoteRegistry{
|
||||||
local: local,
|
local: local,
|
||||||
App: app,
|
App: app,
|
||||||
upstreamProxyConfigRepo: upstreamProxyConfigRepo,
|
upstreamProxyConfigRepo: upstreamProxyConfigRepo,
|
||||||
secretStore: secretStore,
|
spacePathStore: spacePathStore,
|
||||||
encrypter: encrypter,
|
secretService: secretService,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,8 +68,8 @@ type RemoteRegistry struct {
|
||||||
local *LocalRegistry
|
local *LocalRegistry
|
||||||
App *App
|
App *App
|
||||||
upstreamProxyConfigRepo store.UpstreamProxyConfigRepository
|
upstreamProxyConfigRepo store.UpstreamProxyConfigRepository
|
||||||
secretStore store2.SecretStore
|
spacePathStore store2.SpacePathStore
|
||||||
encrypter encrypt.Encrypter
|
secretService secret.Service
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RemoteRegistry) Base() error {
|
func (r *RemoteRegistry) Base() error {
|
||||||
|
@ -150,7 +147,7 @@ func (r *RemoteRegistry) ManifestExist(
|
||||||
responseHeaders *commons.ResponseHeaders, descriptor manifest.Descriptor, manifestResult manifest.Manifest,
|
responseHeaders *commons.ResponseHeaders, descriptor manifest.Descriptor, manifestResult manifest.Manifest,
|
||||||
errs []error,
|
errs []error,
|
||||||
) {
|
) {
|
||||||
proxyCtl := proxy2.ControllerInstance(r.local, r.local.ms)
|
proxyCtl := proxy2.ControllerInstance(r.local, r.local.ms, r.secretService, r.spacePathStore)
|
||||||
responseHeaders = &commons.ResponseHeaders{
|
responseHeaders = &commons.ResponseHeaders{
|
||||||
Headers: make(map[string]string),
|
Headers: make(map[string]string),
|
||||||
}
|
}
|
||||||
|
@ -180,7 +177,8 @@ func (r *RemoteRegistry) ManifestExist(
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
return responseHeaders, descriptor, manifestResult, errs
|
return responseHeaders, descriptor, manifestResult, errs
|
||||||
}
|
}
|
||||||
remoteHelper, err := proxy2.NewRemoteHelper(ctx, r.secretStore, r.encrypter, artInfo.RegIdentifier, *upstreamProxy)
|
remoteHelper, err := proxy2.NewRemoteHelper(ctx, r.spacePathStore, r.secretService, artInfo.RegIdentifier,
|
||||||
|
*upstreamProxy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errs = append(errs, errors.New("Proxy is down"))
|
errs = append(errs, errors.New("Proxy is down"))
|
||||||
return responseHeaders, descriptor, manifestResult, errs
|
return responseHeaders, descriptor, manifestResult, errs
|
||||||
|
@ -239,7 +237,7 @@ func (r *RemoteRegistry) PullManifest(
|
||||||
responseHeaders *commons.ResponseHeaders, descriptor manifest.Descriptor, manifestResult manifest.Manifest,
|
responseHeaders *commons.ResponseHeaders, descriptor manifest.Descriptor, manifestResult manifest.Manifest,
|
||||||
errs []error,
|
errs []error,
|
||||||
) {
|
) {
|
||||||
proxyCtl := proxy2.ControllerInstance(r.local, r.local.ms)
|
proxyCtl := proxy2.ControllerInstance(r.local, r.local.ms, r.secretService, r.spacePathStore)
|
||||||
responseHeaders = &commons.ResponseHeaders{
|
responseHeaders = &commons.ResponseHeaders{
|
||||||
Headers: make(map[string]string),
|
Headers: make(map[string]string),
|
||||||
}
|
}
|
||||||
|
@ -268,7 +266,8 @@ func (r *RemoteRegistry) PullManifest(
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
return responseHeaders, descriptor, manifestResult, errs
|
return responseHeaders, descriptor, manifestResult, errs
|
||||||
}
|
}
|
||||||
remoteHelper, err := proxy2.NewRemoteHelper(ctx, r.secretStore, r.encrypter, artInfo.RegIdentifier, *upstreamProxy)
|
remoteHelper, err := proxy2.NewRemoteHelper(ctx, r.spacePathStore, r.secretService, artInfo.RegIdentifier,
|
||||||
|
*upstreamProxy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errs = append(errs, errors.New("Proxy is down"))
|
errs = append(errs, errors.New("Proxy is down"))
|
||||||
return responseHeaders, descriptor, manifestResult, errs
|
return responseHeaders, descriptor, manifestResult, errs
|
||||||
|
@ -353,7 +352,7 @@ func (r *RemoteRegistry) fetchBlobInternal(
|
||||||
responseHeaders *commons.ResponseHeaders, fr *storage.FileReader, size int64, readCloser io.ReadCloser,
|
responseHeaders *commons.ResponseHeaders, fr *storage.FileReader, size int64, readCloser io.ReadCloser,
|
||||||
redirectURL string, errs []error,
|
redirectURL string, errs []error,
|
||||||
) {
|
) {
|
||||||
proxyCtl := proxy2.ControllerInstance(r.local, r.local.ms)
|
proxyCtl := proxy2.ControllerInstance(r.local, r.local.ms, r.secretService, r.spacePathStore)
|
||||||
responseHeaders = &commons.ResponseHeaders{
|
responseHeaders = &commons.ResponseHeaders{
|
||||||
Headers: make(map[string]string),
|
Headers: make(map[string]string),
|
||||||
}
|
}
|
||||||
|
@ -399,7 +398,7 @@ func (r *RemoteRegistry) fetchBlobInternal(
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is start of proxy Code.
|
// This is start of proxy Code.
|
||||||
size, readCloser, err = proxyCtl.ProxyBlob(ctx, r.secretStore, r.encrypter, registryInfo, repoKey, *upstreamProxy)
|
size, readCloser, err = proxyCtl.ProxyBlob(ctx, registryInfo, repoKey, *upstreamProxy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
return responseHeaders, fr, size, readCloser, redirectURL, errs
|
return responseHeaders, fr, size, readCloser, redirectURL, errs
|
||||||
|
|
|
@ -17,12 +17,12 @@ package docker
|
||||||
import (
|
import (
|
||||||
"github.com/harness/gitness/app/auth/authz"
|
"github.com/harness/gitness/app/auth/authz"
|
||||||
corestore "github.com/harness/gitness/app/store"
|
corestore "github.com/harness/gitness/app/store"
|
||||||
"github.com/harness/gitness/encrypt"
|
|
||||||
storagedriver "github.com/harness/gitness/registry/app/driver"
|
storagedriver "github.com/harness/gitness/registry/app/driver"
|
||||||
"github.com/harness/gitness/registry/app/pkg"
|
"github.com/harness/gitness/registry/app/pkg"
|
||||||
"github.com/harness/gitness/registry/app/storage"
|
"github.com/harness/gitness/registry/app/storage"
|
||||||
"github.com/harness/gitness/registry/app/store"
|
"github.com/harness/gitness/registry/app/store"
|
||||||
"github.com/harness/gitness/registry/gc"
|
"github.com/harness/gitness/registry/gc"
|
||||||
|
"github.com/harness/gitness/secret"
|
||||||
"github.com/harness/gitness/store/database/dbtx"
|
"github.com/harness/gitness/store/database/dbtx"
|
||||||
"github.com/harness/gitness/types"
|
"github.com/harness/gitness/types"
|
||||||
|
|
||||||
|
@ -58,9 +58,9 @@ func ManifestServiceProvider(
|
||||||
|
|
||||||
func RemoteRegistryProvider(
|
func RemoteRegistryProvider(
|
||||||
local *LocalRegistry, app *App, upstreamProxyConfigRepo store.UpstreamProxyConfigRepository,
|
local *LocalRegistry, app *App, upstreamProxyConfigRepo store.UpstreamProxyConfigRepository,
|
||||||
secretStore corestore.SecretStore, encrypter encrypt.Encrypter,
|
spacePathStore corestore.SpacePathStore, secretService secret.Service,
|
||||||
) *RemoteRegistry {
|
) *RemoteRegistry {
|
||||||
return NewRemoteRegistry(local, app, upstreamProxyConfigRepo, secretStore, encrypter).(*RemoteRegistry)
|
return NewRemoteRegistry(local, app, upstreamProxyConfigRepo, spacePathStore, secretService).(*RemoteRegistry)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ControllerProvider(
|
func ControllerProvider(
|
||||||
|
|
|
@ -23,9 +23,9 @@ import (
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
store2 "github.com/harness/gitness/app/store"
|
store2 "github.com/harness/gitness/app/store"
|
||||||
"github.com/harness/gitness/encrypt"
|
|
||||||
"github.com/harness/gitness/registry/app/manifest"
|
"github.com/harness/gitness/registry/app/manifest"
|
||||||
"github.com/harness/gitness/registry/types"
|
"github.com/harness/gitness/registry/types"
|
||||||
|
"github.com/harness/gitness/secret"
|
||||||
)
|
)
|
||||||
|
|
||||||
// const definition.
|
// const definition.
|
||||||
|
@ -39,8 +39,7 @@ var registryKeys = []string{}
|
||||||
// Factory creates a specific Adapter according to the params.
|
// Factory creates a specific Adapter according to the params.
|
||||||
type Factory interface {
|
type Factory interface {
|
||||||
Create(
|
Create(
|
||||||
ctx context.Context, secretStore store2.SecretStore, encrypter encrypt.Encrypter,
|
ctx context.Context, spacePathStore store2.SpacePathStore, record types.UpstreamProxy, service secret.Service,
|
||||||
record types.UpstreamProxy,
|
|
||||||
) (Adapter, error)
|
) (Adapter, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,10 +20,10 @@ import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
store2 "github.com/harness/gitness/app/store"
|
store2 "github.com/harness/gitness/app/store"
|
||||||
"github.com/harness/gitness/encrypt"
|
|
||||||
adp "github.com/harness/gitness/registry/app/remote/adapter"
|
adp "github.com/harness/gitness/registry/app/remote/adapter"
|
||||||
"github.com/harness/gitness/registry/app/remote/adapter/native"
|
"github.com/harness/gitness/registry/app/remote/adapter/native"
|
||||||
"github.com/harness/gitness/registry/types"
|
"github.com/harness/gitness/registry/types"
|
||||||
|
"github.com/harness/gitness/secret"
|
||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
@ -38,10 +38,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func newAdapter(
|
func newAdapter(
|
||||||
ctx context.Context,
|
ctx context.Context, spacePathStore store2.SpacePathStore, service secret.Service, registry types.UpstreamProxy,
|
||||||
secretStore store2.SecretStore,
|
|
||||||
encrypter encrypt.Encrypter,
|
|
||||||
registry types.UpstreamProxy,
|
|
||||||
) (adp.Adapter, error) {
|
) (adp.Adapter, error) {
|
||||||
client, err := NewClient(registry)
|
client, err := NewClient(registry)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -51,7 +48,7 @@ func newAdapter(
|
||||||
// TODO: get Upstream Credentials
|
// TODO: get Upstream Credentials
|
||||||
return &adapter{
|
return &adapter{
|
||||||
client: client,
|
client: client,
|
||||||
Adapter: native.NewAdapter(ctx, secretStore, encrypter, registry),
|
Adapter: native.NewAdapter(ctx, spacePathStore, service, registry),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,12 +57,9 @@ type factory struct {
|
||||||
|
|
||||||
// Create ...
|
// Create ...
|
||||||
func (f *factory) Create(
|
func (f *factory) Create(
|
||||||
ctx context.Context,
|
ctx context.Context, spacePathStore store2.SpacePathStore, record types.UpstreamProxy, service secret.Service,
|
||||||
secretStore store2.SecretStore,
|
|
||||||
encrypter encrypt.Encrypter,
|
|
||||||
record types.UpstreamProxy,
|
|
||||||
) (adp.Adapter, error) {
|
) (adp.Adapter, error) {
|
||||||
return newAdapter(ctx, secretStore, encrypter, record)
|
return newAdapter(ctx, spacePathStore, service, record)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -19,14 +19,13 @@ package native
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
s "github.com/harness/gitness/app/api/controller/secret"
|
|
||||||
"github.com/harness/gitness/app/store"
|
"github.com/harness/gitness/app/store"
|
||||||
"github.com/harness/gitness/encrypt"
|
|
||||||
api "github.com/harness/gitness/registry/app/api/openapi/contracts/artifact"
|
api "github.com/harness/gitness/registry/app/api/openapi/contracts/artifact"
|
||||||
"github.com/harness/gitness/registry/app/common/lib/errors"
|
"github.com/harness/gitness/registry/app/common/lib/errors"
|
||||||
adp "github.com/harness/gitness/registry/app/remote/adapter"
|
adp "github.com/harness/gitness/registry/app/remote/adapter"
|
||||||
"github.com/harness/gitness/registry/app/remote/clients/registry"
|
"github.com/harness/gitness/registry/app/remote/clients/registry"
|
||||||
"github.com/harness/gitness/registry/types"
|
"github.com/harness/gitness/registry/types"
|
||||||
|
"github.com/harness/gitness/secret"
|
||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
@ -47,16 +46,13 @@ type Adapter struct {
|
||||||
|
|
||||||
// NewAdapter returns an instance of the Adapter.
|
// NewAdapter returns an instance of the Adapter.
|
||||||
func NewAdapter(
|
func NewAdapter(
|
||||||
ctx context.Context,
|
ctx context.Context, spacePathStore store.SpacePathStore, service secret.Service, reg types.UpstreamProxy,
|
||||||
secretStore store.SecretStore,
|
|
||||||
encrypter encrypt.Encrypter,
|
|
||||||
reg types.UpstreamProxy,
|
|
||||||
) *Adapter {
|
) *Adapter {
|
||||||
adapter := &Adapter{
|
adapter := &Adapter{
|
||||||
proxy: reg,
|
proxy: reg,
|
||||||
}
|
}
|
||||||
// Get the password: lookup secrets.secret_data using secret_identifier & secret_space_id.
|
// Get the password: lookup secrets.secret_data using secret_identifier & secret_space_id.
|
||||||
password := getPwd(ctx, secretStore, encrypter, reg)
|
password := getPwd(ctx, spacePathStore, service, reg)
|
||||||
username, password, url := reg.UserName, password, reg.RepoURL
|
username, password, url := reg.UserName, password, reg.RepoURL
|
||||||
adapter.Client = registry.NewClient(url, username, password, false)
|
adapter.Client = registry.NewClient(url, username, password, false)
|
||||||
return adapter
|
return adapter
|
||||||
|
@ -64,12 +60,8 @@ func NewAdapter(
|
||||||
|
|
||||||
// getPwd: lookup secrets.secret_data using secret_identifier & secret_space_id.
|
// getPwd: lookup secrets.secret_data using secret_identifier & secret_space_id.
|
||||||
func getPwd(
|
func getPwd(
|
||||||
ctx context.Context,
|
ctx context.Context, spacePathStore store.SpacePathStore, secretService secret.Service, reg types.UpstreamProxy,
|
||||||
secretStore store.SecretStore,
|
|
||||||
encrypter encrypt.Encrypter,
|
|
||||||
reg types.UpstreamProxy,
|
|
||||||
) string {
|
) string {
|
||||||
password := ""
|
|
||||||
if api.AuthType(reg.RepoAuthType) == api.AuthTypeUserPassword {
|
if api.AuthType(reg.RepoAuthType) == api.AuthTypeUserPassword {
|
||||||
secretSpaceID := int64(0)
|
secretSpaceID := int64(0)
|
||||||
if reg.SecretSpaceID.Valid {
|
if reg.SecretSpaceID.Valid {
|
||||||
|
@ -80,17 +72,20 @@ func getPwd(
|
||||||
if reg.SecretIdentifier.Valid {
|
if reg.SecretIdentifier.Valid {
|
||||||
secretIdentifier = reg.SecretIdentifier.String
|
secretIdentifier = reg.SecretIdentifier.String
|
||||||
}
|
}
|
||||||
secret, err := secretStore.FindByIdentifier(ctx, secretSpaceID, secretIdentifier)
|
|
||||||
|
spacePath, err := spacePathStore.FindPrimaryBySpaceID(ctx, secretSpaceID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Msgf("failed to find secret: %v", err)
|
log.Error().Msgf("failed to find space path: %v", err)
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
secret, err = s.Dec(encrypter, secret)
|
decryptSecret, err := secretService.DecryptSecret(ctx, spacePath.Value, secretIdentifier)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Msgf("could not decrypt secret: %v", err)
|
log.Error().Msgf("failed to decrypt secret: %v", err)
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
password = secret.Data
|
return decryptSecret
|
||||||
}
|
}
|
||||||
return password
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// HealthCheck checks health status of a proxy.
|
// HealthCheck checks health status of a proxy.
|
||||||
|
|
|
@ -26,13 +26,13 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/harness/gitness/app/api/request"
|
"github.com/harness/gitness/app/api/request"
|
||||||
store2 "github.com/harness/gitness/app/store"
|
"github.com/harness/gitness/app/store"
|
||||||
"github.com/harness/gitness/encrypt"
|
|
||||||
"github.com/harness/gitness/registry/app/common/lib/errors"
|
"github.com/harness/gitness/registry/app/common/lib/errors"
|
||||||
"github.com/harness/gitness/registry/app/manifest"
|
"github.com/harness/gitness/registry/app/manifest"
|
||||||
"github.com/harness/gitness/registry/app/pkg"
|
"github.com/harness/gitness/registry/app/pkg"
|
||||||
"github.com/harness/gitness/registry/app/pkg/commons"
|
"github.com/harness/gitness/registry/app/pkg/commons"
|
||||||
"github.com/harness/gitness/registry/types"
|
"github.com/harness/gitness/registry/types"
|
||||||
|
"github.com/harness/gitness/secret"
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3/registry/api/errcode"
|
"github.com/distribution/distribution/v3/registry/api/errcode"
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
|
@ -68,12 +68,7 @@ type Controller interface {
|
||||||
// ProxyBlob proxy the blob request to the remote server, p is the proxy project
|
// ProxyBlob proxy the blob request to the remote server, p is the proxy project
|
||||||
// art is the RegistryInfo which includes the digest of the blob
|
// art is the RegistryInfo which includes the digest of the blob
|
||||||
ProxyBlob(
|
ProxyBlob(
|
||||||
ctx context.Context,
|
ctx context.Context, art pkg.RegistryInfo, repoKey string, proxy types.UpstreamProxy,
|
||||||
secretStore store2.SecretStore,
|
|
||||||
encrypter encrypt.Encrypter,
|
|
||||||
art pkg.RegistryInfo,
|
|
||||||
repoKey string,
|
|
||||||
proxy types.UpstreamProxy,
|
|
||||||
) (int64, io.ReadCloser, error)
|
) (int64, io.ReadCloser, error)
|
||||||
// ProxyManifest proxy the manifest request to the remote server, p is the proxy project,
|
// ProxyManifest proxy the manifest request to the remote server, p is the proxy project,
|
||||||
// art is the RegistryInfo which includes the tag or digest of the manifest
|
// art is the RegistryInfo which includes the tag or digest of the manifest
|
||||||
|
@ -99,21 +94,24 @@ type Controller interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type controller struct {
|
type controller struct {
|
||||||
// blobCtl blob.Controller
|
|
||||||
// artifactCtl artifact.Controller.
|
|
||||||
localRegistry registryInterface
|
localRegistry registryInterface
|
||||||
localManifestRegistry registryManifestInterface
|
localManifestRegistry registryManifestInterface
|
||||||
// cache cache.Cache
|
secretService secret.Service
|
||||||
// handlerRegistry map[string]ManifestCacheHandler.
|
spacePathStore store.SpacePathStore
|
||||||
}
|
}
|
||||||
|
|
||||||
// ControllerInstance -- get the proxy controller instance.
|
// ControllerInstance -- get the proxy controller instance.
|
||||||
func ControllerInstance(l registryInterface, lm registryManifestInterface) Controller {
|
func ControllerInstance(
|
||||||
|
l registryInterface, lm registryManifestInterface, secretService secret.Service,
|
||||||
|
spacePathStore store.SpacePathStore,
|
||||||
|
) Controller {
|
||||||
once.Do(
|
once.Do(
|
||||||
func() {
|
func() {
|
||||||
ctl = &controller{
|
ctl = &controller{
|
||||||
localRegistry: l,
|
localRegistry: l,
|
||||||
localManifestRegistry: lm,
|
localManifestRegistry: lm,
|
||||||
|
secretService: secretService,
|
||||||
|
spacePathStore: spacePathStore,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -294,17 +292,12 @@ func (c *controller) HeadManifest(
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *controller) ProxyBlob(
|
func (c *controller) ProxyBlob(
|
||||||
ctx context.Context,
|
ctx context.Context, art pkg.RegistryInfo, repoKey string, proxy types.UpstreamProxy,
|
||||||
secretStore store2.SecretStore,
|
|
||||||
encrypter encrypt.Encrypter,
|
|
||||||
art pkg.RegistryInfo,
|
|
||||||
repoKey string,
|
|
||||||
proxy types.UpstreamProxy,
|
|
||||||
) (int64, io.ReadCloser, error) {
|
) (int64, io.ReadCloser, error) {
|
||||||
remoteImage := getRemoteRepo(art)
|
remoteImage := getRemoteRepo(art)
|
||||||
log.Debug().Msgf("The blob doesn't exist, proxy the request to the target server, url:%v", remoteImage)
|
log.Debug().Msgf("The blob doesn't exist, proxy the request to the target server, url:%v", remoteImage)
|
||||||
|
|
||||||
rHelper, err := NewRemoteHelper(ctx, secretStore, encrypter, repoKey, proxy)
|
rHelper, err := NewRemoteHelper(ctx, c.spacePathStore, c.secretService, repoKey, proxy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil, err
|
return 0, nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,11 +20,11 @@ import (
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/harness/gitness/app/store"
|
"github.com/harness/gitness/app/store"
|
||||||
"github.com/harness/gitness/encrypt"
|
|
||||||
api "github.com/harness/gitness/registry/app/api/openapi/contracts/artifact"
|
api "github.com/harness/gitness/registry/app/api/openapi/contracts/artifact"
|
||||||
"github.com/harness/gitness/registry/app/manifest"
|
"github.com/harness/gitness/registry/app/manifest"
|
||||||
"github.com/harness/gitness/registry/app/remote/adapter"
|
"github.com/harness/gitness/registry/app/remote/adapter"
|
||||||
"github.com/harness/gitness/registry/types"
|
"github.com/harness/gitness/registry/types"
|
||||||
|
"github.com/harness/gitness/secret"
|
||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
@ -52,14 +52,12 @@ type remoteHelper struct {
|
||||||
registry adapter.ArtifactRegistry
|
registry adapter.ArtifactRegistry
|
||||||
upstreamProxy types.UpstreamProxy
|
upstreamProxy types.UpstreamProxy
|
||||||
URL string
|
URL string
|
||||||
|
secretService secret.Service
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRemoteHelper create a remote interface.
|
// NewRemoteHelper create a remote interface.
|
||||||
func NewRemoteHelper(
|
func NewRemoteHelper(
|
||||||
ctx context.Context,
|
ctx context.Context, spacePathStore store.SpacePathStore, secretService secret.Service, repoKey string,
|
||||||
secretStore store.SecretStore,
|
|
||||||
encrypter encrypt.Encrypter,
|
|
||||||
repoKey string,
|
|
||||||
proxy types.UpstreamProxy,
|
proxy types.UpstreamProxy,
|
||||||
) (RemoteInterface, error) {
|
) (RemoteInterface, error) {
|
||||||
if proxy.Source == string(api.UpstreamConfigSourceDockerhub) {
|
if proxy.Source == string(api.UpstreamConfigSourceDockerhub) {
|
||||||
|
@ -68,14 +66,15 @@ func NewRemoteHelper(
|
||||||
r := &remoteHelper{
|
r := &remoteHelper{
|
||||||
repoKey: repoKey,
|
repoKey: repoKey,
|
||||||
upstreamProxy: proxy,
|
upstreamProxy: proxy,
|
||||||
|
secretService: secretService,
|
||||||
}
|
}
|
||||||
if err := r.init(ctx, secretStore, encrypter); err != nil {
|
if err := r.init(ctx, spacePathStore); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return r, nil
|
return r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *remoteHelper) init(ctx context.Context, secretStore store.SecretStore, encrypter encrypt.Encrypter) error {
|
func (r *remoteHelper) init(ctx context.Context, spacePathStore store.SpacePathStore) error {
|
||||||
if r.registry != nil {
|
if r.registry != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -85,7 +84,7 @@ func (r *remoteHelper) init(ctx context.Context, secretStore store.SecretStore,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
adp, err := factory.Create(ctx, secretStore, encrypter, r.upstreamProxy)
|
adp, err := factory.Create(ctx, spacePathStore, r.upstreamProxy, r.secretService)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
// Copyright 2023 Harness, Inc.
|
||||||
|
//
|
||||||
|
// 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 secret
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Service interface {
|
||||||
|
DecryptSecret(ctx context.Context, spacePath, secretIdentifier string) (string, error)
|
||||||
|
}
|
Loading…
Reference in New Issue