secrets

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// ControllerRole / ControllerServiceAccount 는 백엔드가 사용하는 신원이다.
	// 부트스트랩 Job 이 만드는 role/SA 이름과 일치해야 한다.
	ControllerRole           = "nullus-controller"
	ControllerServiceAccount = "nullus-controller"
)
View Source
const DefaultEnv = "dev"

DefaultEnv 는 환경 이름이 비었을 때 쓰는 값이다.

View Source
const PipelineCredentialsPolicyPath = "metadata/nullus/+/+/cicd/pipelines/+/+"

PipelineCredentialsPolicyPath 는 컨트롤러가 지울 수 있는 파이프라인 자격증명의 정책 경로다 (KV 마운트 뒤). 스택 모듈이 부트스트랩 정책에 쓰고, cicd 모듈은 PipelineCredentialPrefix 로 같은 깊이에 값을 쓴다.

끝을 * 가 아니라 + 로 둔다. OpenBao 는 맞는 규칙 중 가장 구체적인 하나만 쓰는데, 끝이 * 이면서 + 가 많은 규칙은 nullus/* 보다 우선순위가 낮아 delete 가 무시된다(OpenBao 2.5.5 확인).

Variables

View Source
var ErrProviderNotConfigured = errors.New("secret provider not configured")

Functions

func GitHubAPITokenPath

func GitHubAPITokenPath(env, orgID string) string

GitHubAPITokenPath 는 조직 GitHub PAT 의 경로다.

func GitLabAPITokenPath

func GitLabAPITokenPath(env, orgID string) string

GitLabAPITokenPath 는 스택 GitLab 자동화 토큰의 경로다.

func IsForbidden added in v0.6.0

func IsForbidden(err error) bool

IsForbidden 은 금고 정책이 막았는지(403) 알려준다.

func IsNotFound added in v0.6.0

func IsNotFound(err error) bool

IsNotFound 는 404 인지 알려준다.

func IsPathSegment added in v0.6.0

func IsPathSegment(s string) bool

IsPathSegment 는 경로의 한 세그먼트로 안전한지 본다 — 비어 있지 않고, 구분자가 없고, "." · ".." 이 아니다.

func PipelineCredentialPrefix added in v0.6.0

func PipelineCredentialPrefix(env, orgID, app string) (string, error)

PipelineCredentialPrefix 는 한 파이프라인의 자격증명이 사는 경로다(끝이 /).

앱 이름은 경로의 한 세그먼트여야 한다. "..", "/" 가 들어가면 경로가 다른 파이프라인의 값을 가리킨다 — client-go 의 proxy 요청은 경로를 정리(path.Join)해서 보낸다. 조직이 비면 예전부터 쓰던 "default" 다.

Types

type HealthChecker

type HealthChecker interface {
	Check(ctx context.Context) error
}

type KVBrowser added in v0.6.0

type KVBrowser interface {
	ListKeys(ctx context.Context, path string) ([]string, error)
	GetSecret(ctx context.Context, path string) (map[string]any, error)
	PutSecret(ctx context.Context, path string, data map[string]any) error
}

KVBrowser 는 KV 트리를 훑고 값을 통째로 읽고 쓰는 확장 창구다.

Store 인터페이스를 넓히지 않고 별도 인터페이스로 둔 이유: 이 능력이 필요한 곳은 백업뿐이고, 토큰만 다루는 대다수 호출자에게 강제할 이유가 없다.

type KVDeleter added in v0.6.0

type KVDeleter interface {
	ListKeys(ctx context.Context, path string) ([]string, error)
	DeleteSecret(ctx context.Context, path string) error
}

KVDeleter 는 KV 트리를 지우는 확장 창구다. 파이프라인을 지울 때 그 파이프라인 몫의 자격증명을 회수하는 데 쓴다 — Store 를 넓히지 않는 이유는 KVBrowser 와 같다.

type KubernetesAuthConfig

type KubernetesAuthConfig struct {
	Kubeconfig     []byte
	Namespace      string
	Role           string
	ServiceAccount string
	// ServiceName/ServicePort 가 비면 openbao:8200 을 사용한다.
	ServiceName string
	ServicePort string
}

KubernetesAuthConfig 는 k8s auth 로그인에 필요한 정보를 담는다.

type KubernetesTokenProvider

type KubernetesTokenProvider struct {
	// contains filtered or unexported fields
}

KubernetesTokenProvider 는 Kubernetes Auth 로 로그인해 얻은 client_token 을 캐시하고, 만료가 임박하면 다시 로그인한다.

login 은 (토큰, TTL, 오류) 를 돌려준다. 테스트에서 교체할 수 있도록 필드로 주입한다.

func NewKubernetesTokenProvider

func NewKubernetesTokenProvider(login func(ctx context.Context) (string, time.Duration, error)) *KubernetesTokenProvider

NewKubernetesTokenProvider 는 주어진 로그인 함수로 provider 를 만든다.

func (*KubernetesTokenProvider) Token

type OpenBaoStore

type OpenBaoStore struct {
	// contains filtered or unexported fields
}

func NewKubernetesAuthStore

func NewKubernetesAuthStore(cfg KubernetesAuthConfig) (*OpenBaoStore, error)

NewKubernetesAuthStore 는 대상 클러스터의 OpenBao 에 Kubernetes Auth 로 접속하는 store 를 만든다.

func NewOpenBaoStore

func NewOpenBaoStore(addr, token string) *OpenBaoStore

NewOpenBaoStore 는 정적 토큰을 사용하는 store 를 만든다. 로컬 개발 전용이다.

func NewOpenBaoStoreWithProvider

func NewOpenBaoStoreWithProvider(addr string, provider TokenProvider) *OpenBaoStore

NewOpenBaoStoreWithProvider 는 토큰 공급 전략을 주입해 store 를 만든다. 운영 경로는 KubernetesTokenProvider 를 넘겨 단기 자격을 사용한다.

func (*OpenBaoStore) Check

func (s *OpenBaoStore) Check(ctx context.Context) error

Check 는 금고가 응답하고, 봉인이 풀려 있고, 자격이 유효한지 확인한다. preflight gate 의 판단 근거다.

func (*OpenBaoStore) DeleteSecret added in v0.6.0

func (s *OpenBaoStore) DeleteSecret(ctx context.Context, path string) error

DeleteSecret 은 경로의 값을 모든 버전과 함께 지운다. 이미 없으면 성공이다.

KV v2 에서 data 를 지우면 최신 버전만 지워지고 경로는 목록에 남는다. 회수는 metadata 를 지워야 끝난다.

func (*OpenBaoStore) GetSecret added in v0.6.0

func (s *OpenBaoStore) GetSecret(ctx context.Context, path string) (map[string]any, error)

GetSecret 은 경로의 값 전체를 돌려준다 (token 필드만이 아니라).

func (*OpenBaoStore) GetToken

func (s *OpenBaoStore) GetToken(ctx context.Context, path string) (string, error)

func (*OpenBaoStore) ListKeys added in v0.6.0

func (s *OpenBaoStore) ListKeys(ctx context.Context, path string) ([]string, error)

ListKeys 는 경로 바로 아래의 항목을 돌려준다. 디렉터리는 "/" 로 끝난다.

func (*OpenBaoStore) PutSecret added in v0.6.0

func (s *OpenBaoStore) PutSecret(ctx context.Context, path string, data map[string]any) error

PutSecret 은 값 전체를 쓴다.

func (*OpenBaoStore) PutToken

func (s *OpenBaoStore) PutToken(ctx context.Context, path, value string) error

type Resolver

type Resolver interface {
	Resolve(ctx context.Context, provider, stackID string) (Store, error)
}

Resolver 는 스택 단위로 Store 를 만들어 준다.

OpenBao 는 스택마다 배포되므로 "provider 하나 = 인스턴스 하나" 가정이 성립하지 않는다. Router 는 전역 등록(로컬 개발)과 스택별 지연 생성(운영)을 함께 지원한다.

type Router

type Router struct {
	// contains filtered or unexported fields
}

func NewRouter

func NewRouter() *Router

func (*Router) Check

func (r *Router) Check(ctx context.Context, provider string) error

func (*Router) CheckForStack

func (r *Router) CheckForStack(ctx context.Context, provider, stackID string) error

func (*Router) DeleteTreeForStack added in v0.6.0

func (r *Router) DeleteTreeForStack(ctx context.Context, provider, stackID, prefix string) error

DeleteTreeForStack 은 접두사 아래의 값을 하위 디렉터리까지 모두 지운다. 없으면 성공이다.

하나를 못 지워도 나머지는 지운다 — 중간에 멈추면 무엇이 남았는지 알 수 없다.

func (*Router) ForStack

func (r *Router) ForStack(ctx context.Context, provider, stackID string) (Store, error)

ForStack 은 특정 스택의 Store 를 돌려준다. resolver 가 없거나 stackID 가 비면 전역 등록분으로 되돌아간다.

func (*Router) GetToken

func (r *Router) GetToken(ctx context.Context, provider, path string) (string, error)

func (*Router) GetTokenForStack

func (r *Router) GetTokenForStack(ctx context.Context, provider, stackID, path string) (string, error)

func (*Router) Has

func (r *Router) Has(provider string) bool

Has 는 전역 등록 또는 스택별 resolver 중 하나라도 있으면 true 다.

func (*Router) InvalidateStack

func (r *Router) InvalidateStack(stackID string)

InvalidateStack 은 스택 삭제/재설치 시 캐시된 Store 를 버린다.

func (*Router) PutToken

func (r *Router) PutToken(ctx context.Context, provider, path, value string) error

func (*Router) PutTokenForStack

func (r *Router) PutTokenForStack(ctx context.Context, provider, stackID, path, value string) error

PutTokenForStack / GetTokenForStack / CheckForStack 은 스택 범위 접근이다.

func (*Router) Register

func (r *Router) Register(provider string, store Store)

func (*Router) WithResolver

func (r *Router) WithResolver(resolver Resolver) *Router

WithResolver 는 스택별 Store 생성기를 등록한다.

type StaticTokenProvider

type StaticTokenProvider struct {
	// contains filtered or unexported fields
}

StaticTokenProvider 는 고정 토큰을 돌려준다. 로컬 개발 전용이다.

func NewStaticTokenProvider

func NewStaticTokenProvider(token string) *StaticTokenProvider

func (*StaticTokenProvider) Token

type StatusError added in v0.6.0

type StatusError struct {
	Status int
	Body   string
}

StatusError 는 금고가 돌려준 HTTP 오류다.

상태 코드를 타입으로 노출하는 이유: KV 트리를 훑을 때 404("하위가 없다")와 403/500("읽을 수 없다")를 구분해야 한다. 뭉뚱그리면 권한이 막힌 서브트리가 조용히 백업에서 빠지고, 그 사실은 복구할 때에야 드러난다.

func (*StatusError) Error added in v0.6.0

func (e *StatusError) Error() string

type Store

type Store interface {
	PutToken(ctx context.Context, path, value string) error
	GetToken(ctx context.Context, path string) (string, error)
}

type TokenProvider

type TokenProvider interface {
	Token(ctx context.Context) (string, error)
}

TokenProvider 는 OpenBao 요청에 사용할 토큰을 공급한다.

구현이 두 가지인 이유는 실행 위치가 다르기 때문이다.

  • StaticTokenProvider: 로컬 개발 전용. .env 의 고정 토큰을 그대로 쓴다
  • KubernetesTokenProvider: 운영. Kubernetes Auth 로 단기 자격을 발급받는다

PRD 5.2 는 "정적 토큰 하드코딩 금지, Kubernetes auth 기반 short-lived token 사용을 기본으로 한다" 고 규정한다. 정적 전략은 로컬 예외로만 허용된다.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL