summaryrefslogtreecommitdiffstats
path: root/pkg/signature/options/rpcauth.go
blob: 188de92dc96f0e75743fa587fb31236338a86cc1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//
// Copyright 2021 The Sigstore Authors.
//
// 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 options

// RPCAuthOpts includes authentication settings for RPC calls
type RPCAuthOpts struct {
	NoOpOptionImpl
	opts RPCAuth
}

// RPCAuth provides credentials for RPC calls, empty fields are ignored
type RPCAuth struct {
	Address string // address is the remote server address, e.g. https://vault:8200
	Path    string // path for the RPC, in vault this is the transit path which default to "transit"
	Token   string // token used for RPC, in vault this is the VAULT_TOKEN value
	OIDC    RPCAuthOIDC
}

// RPCAuthOIDC is used to perform the RPC login using OIDC instead of a fixed token
type RPCAuthOIDC struct {
	Path  string // path defaults to "jwt" for vault
	Role  string // role is required for jwt logins
	Token string // token is a jwt with vault
}

// ApplyRPCAuthOpts sets the RPCAuth as a function option
func (r RPCAuthOpts) ApplyRPCAuthOpts(opts *RPCAuth) {
	if r.opts.Address != "" {
		opts.Address = r.opts.Address
	}
	if r.opts.Path != "" {
		opts.Path = r.opts.Path
	}
	if r.opts.Token != "" {
		opts.Token = r.opts.Token
	}
	if r.opts.OIDC.Token != "" {
		opts.OIDC = r.opts.OIDC
	}
}

// WithRPCAuthOpts specifies RPCAuth settings to be used with RPC logins
func WithRPCAuthOpts(opts RPCAuth) RPCAuthOpts {
	return RPCAuthOpts{opts: opts}
}