Skip to content

Commit 1e9b6d1

Browse files
committed
Add bind dev cli command
1 parent f66ba4f commit 1e9b6d1

38 files changed

Lines changed: 2350 additions & 754 deletions

Makefile

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,6 @@ fix-lint: $(GOLANGCI_LINT) ## Run golangci-lint with --fix
171171
GOLANGCI_LINT_FLAGS="--fix" $(MAKE) lint
172172
.PHONY: fix-lint
173173

174-
vendor: ## Vendor the dependencies
175-
go mod tidy
176-
go mod vendor
177-
.PHONY: vendor
178-
179174
tools: $(GOLANGCI_LINT) $(CONTROLLER_GEN) $(YAML_PATCH) $(GOTESTSUM) $(CODE_GENERATOR) ## Install tools
180175
.PHONY: tools
181176

@@ -351,20 +346,9 @@ verify-imports: imports
351346
verify-go-versions:
352347
hack/verify-go-versions.sh
353348

354-
.PHONY: modules
355-
modules: ## Run go mod tidy to ensure modules are up to date
356-
for MOD in $(GOMODS); do \
357-
(cd $$MOD; echo "Tidying $$MOD"; go mod tidy); \
358-
done
359-
360-
.PHONY: verify-modules
361-
verify-modules: modules # Verify go modules are up to date
362-
@for MOD in $(GOMODS); do \
363-
(cd $$MOD; echo "Verifying $$MOD"; if ! git diff --quiet HEAD -- go.mod go.sum; then git diff -- go.mod go.sum; echo "[$$MOD] go modules are out of date, please run 'make modules'"; exit 1; fi; ) \
364-
done
365349

366350
.PHONY: verify
367-
verify: verify-modules verify-go-versions verify-imports verify-codegen verify-boilerplate ## verify formal properties of the code
351+
verify: verify-go-versions verify-imports verify-codegen verify-boilerplate ## verify formal properties of the code
368352

369353
.PHONY: help
370354
help: ## Show this help

backend/oidc/oidc.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import (
2222
"fmt"
2323
"net"
2424
"os"
25-
"path"
2625
"time"
2726

27+
"github.com/davecgh/go-spew/spew"
2828
"github.com/gorilla/mux"
2929
"github.com/xrstf/mockoidc"
3030
)
@@ -70,8 +70,9 @@ type Config struct {
7070

7171
CodeChallengeMethodsSupported []string
7272

73-
// CallbackURL is kube-bind specific and must match API server endpoints.
73+
// CallbackURL and IssuerURL are kube-bind specific and must match API server endpoints.
7474
CallbackURL string
75+
IssuerURL string
7576
}
7677

7778
var ErrServerNotRunning = fmt.Errorf("embedded OIDC server is not running")
@@ -85,8 +86,8 @@ func (s *Server) AddRoutes(mux *mux.Router) {
8586
}
8687

8788
// URL returns the base URL of the embedded OIDC server.
88-
func (s *Server) Config() (*Config, error) {
89-
return &Config{
89+
func (s *Server) Config(callbackURL, issuerURL string) (*Config, error) {
90+
c := &Config{
9091
ClientID: s.server.Config().ClientID,
9192
ClientSecret: s.server.Config().ClientSecret,
9293
Issuer: s.server.Config().Issuer,
@@ -95,8 +96,11 @@ func (s *Server) Config() (*Config, error) {
9596
RefreshTTL: s.server.Config().RefreshTTL,
9697

9798
CodeChallengeMethodsSupported: s.server.Config().CodeChallengeMethodsSupported,
98-
CallbackURL: path.Join(s.server.Addr(), "api/callback"),
99-
}, nil
99+
CallbackURL: callbackURL,
100+
IssuerURL: issuerURL,
101+
}
102+
spew.Dump(c)
103+
return c, nil
100104
}
101105

102106
func LoadTLSConfig(caFile string) (*tls.Config, error) {

backend/options/oidc.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,15 @@ import (
2626
"github.com/kube-bind/kube-bind/backend/oidc"
2727
)
2828

29+
type OIDCType string
30+
31+
const (
32+
OIDCTypeEmbedded OIDCType = "embedded"
33+
OIDCTypeExternal OIDCType = "external"
34+
)
35+
2936
type OIDC struct {
37+
Type string
3038
IssuerClientID string
3139
IssuerClientSecret string
3240
IssuerURL string
@@ -50,17 +58,18 @@ func (options *OIDC) AddFlags(fs *pflag.FlagSet) {
5058
fs.StringVar(&options.CallbackURL, "oidc-callback-url", options.CallbackURL, "OpenID callback URL")
5159
fs.StringVar(&options.AuthorizeURL, "oidc-authorize-url", options.AuthorizeURL, "OpenID authorize URL")
5260
fs.StringVar(&options.CAFile, "oidc-ca-file", options.CAFile, "Path to a CA bundle to use when verifying the OIDC provider's TLS certificate.")
61+
fs.StringVar(&options.Type, "oidc-type", options.Type, "Type of OIDC provider (embedded or external)")
5362
}
5463

5564
func (options *OIDC) Complete(listener net.Listener) error {
56-
if options.IssuerURL == "" {
65+
if options.Type == "" || options.Type == string(OIDCTypeEmbedded) {
5766
oidcServer, err := oidc.New(options.CAFile, listener)
5867
if err != nil {
5968
return err
6069
}
6170
options.OIDCServer = oidcServer
6271

63-
cfg, err := oidcServer.Config()
72+
cfg, err := oidcServer.Config(options.CallbackURL, options.IssuerURL)
6473
if err != nil {
6574
return err
6675
}

backend/options/options.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ func (options *CompletedOptions) Validate() error {
228228
return fmt.Errorf("pretty name cannot be empty")
229229
}
230230

231+
if err := options.Serve.Validate(); err != nil {
232+
return err
233+
}
234+
231235
if err := options.OIDC.Validate(); err != nil {
232236
return err
233237
}

backend/options/serve.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ func (options *Serve) Complete() error {
5757
if options.ListenIP != "" {
5858
addr = net.JoinHostPort(options.ListenIP, strconv.Itoa(options.ListenPort))
5959
}
60-
options.Listener, err = net.Listen("tcp", addr)
60+
// We only support TCP4 for now to avoid dual stack complications in embedded OIDC server tests.
61+
options.Listener, err = net.Listen("tcp4", addr)
6162
if err != nil {
6263
return err
6364
}
@@ -66,7 +67,7 @@ func (options *Serve) Complete() error {
6667
}
6768

6869
func (options *Serve) Validate() error {
69-
if (options.ListenIP == "") != (options.ListenAddress == "") {
70+
if options.ListenIP == "" && options.ListenAddress == "" {
7071
return fmt.Errorf("either listen-ip or listen-address must be provided")
7172
}
7273
if options.CertFile == "" && options.KeyFile != "" {

cli/cmd/kubectl-bind/cmd/kubectlBind.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
logincmd "github.com/kube-bind/kube-bind/cli/pkg/kubectl/bind-login/cmd"
3232
templatescmd "github.com/kube-bind/kube-bind/cli/pkg/kubectl/bind-templates/cmd"
3333
bindcmd "github.com/kube-bind/kube-bind/cli/pkg/kubectl/bind/cmd"
34+
devcmd "github.com/kube-bind/kube-bind/cli/pkg/kubectl/dev/cmd"
3435
)
3536

3637
func KubectlBindCommand() *cobra.Command {
@@ -78,5 +79,12 @@ func KubectlBindCommand() *cobra.Command {
7879
}
7980
rootCmd.AddCommand(collectionsCmd)
8081

82+
devCmd, err := devcmd.New(genericclioptions.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr})
83+
if err != nil {
84+
fmt.Fprintf(os.Stderr, "error: %v", err)
85+
os.Exit(1)
86+
}
87+
rootCmd.AddCommand(devCmd)
88+
8189
return rootCmd
8290
}

cli/go.mod

Lines changed: 93 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -10,70 +10,105 @@ replace (
1010
require (
1111
github.com/MakeNowJust/heredoc v1.0.0
1212
github.com/blang/semver/v4 v4.0.0
13+
github.com/docker/docker v28.5.2+incompatible
1314
github.com/fatih/color v1.18.0
1415
github.com/kube-bind/kube-bind v0.0.0-00010101000000-000000000000
1516
github.com/kube-bind/kube-bind/sdk v0.4.1
1617
github.com/muesli/reflow v0.3.0
17-
github.com/spf13/cobra v1.9.1
18-
github.com/spf13/pflag v1.0.6
19-
github.com/stretchr/testify v1.10.0
20-
k8s.io/api v0.33.3
21-
k8s.io/apiextensions-apiserver v0.33.3
22-
k8s.io/apimachinery v0.33.3
23-
k8s.io/cli-runtime v0.32.0
24-
k8s.io/client-go v0.33.3
25-
k8s.io/component-base v0.33.3
18+
github.com/spf13/cobra v1.10.1
19+
github.com/spf13/pflag v1.0.9
20+
github.com/stretchr/testify v1.11.1
21+
helm.sh/helm/v3 v3.19.0
22+
k8s.io/api v0.34.0
23+
k8s.io/apiextensions-apiserver v0.34.0
24+
k8s.io/apimachinery v0.34.0
25+
k8s.io/cli-runtime v0.34.0
26+
k8s.io/client-go v0.34.0
27+
k8s.io/component-base v0.34.0
2628
k8s.io/klog/v2 v2.130.1
27-
sigs.k8s.io/yaml v1.4.0
29+
sigs.k8s.io/kind v0.30.0
30+
sigs.k8s.io/yaml v1.6.0
2831
)
2932

3033
require (
31-
cel.dev/expr v0.19.1 // indirect
32-
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
33-
github.com/NYTimes/gziphandler v1.1.1 // indirect
34-
github.com/antlr4-go/antlr/v4 v4.13.1 // indirect
34+
al.essio.dev/pkg/shellescape v1.5.1 // indirect
35+
dario.cat/mergo v1.0.1 // indirect
36+
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c // indirect
37+
github.com/BurntSushi/toml v1.5.0 // indirect
38+
github.com/Masterminds/goutils v1.1.1 // indirect
39+
github.com/Masterminds/semver/v3 v3.4.0 // indirect
40+
github.com/Masterminds/sprig/v3 v3.3.0 // indirect
41+
github.com/Masterminds/squirrel v1.5.4 // indirect
42+
github.com/Microsoft/go-winio v0.6.2 // indirect
43+
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
3544
github.com/beorn7/perks v1.0.1 // indirect
36-
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
3745
github.com/cespare/xxhash/v2 v2.3.0 // indirect
38-
github.com/coreos/go-semver v0.3.1 // indirect
39-
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
46+
github.com/chai2010/gettext-go v1.0.2 // indirect
47+
github.com/containerd/containerd v1.7.28 // indirect
48+
github.com/containerd/errdefs v0.3.0 // indirect
49+
github.com/containerd/errdefs/pkg v0.3.0 // indirect
50+
github.com/containerd/log v0.1.0 // indirect
51+
github.com/containerd/platforms v0.2.1 // indirect
52+
github.com/cyphar/filepath-securejoin v0.4.1 // indirect
4053
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
41-
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
54+
github.com/distribution/reference v0.6.0 // indirect
55+
github.com/docker/go-connections v0.6.0 // indirect
56+
github.com/docker/go-units v0.5.0 // indirect
57+
github.com/emicklei/go-restful/v3 v3.12.2 // indirect
58+
github.com/evanphx/json-patch v5.9.11+incompatible // indirect
59+
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
60+
github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f // indirect
4261
github.com/felixge/httpsnoop v1.0.4 // indirect
43-
github.com/fsnotify/fsnotify v1.7.0 // indirect
44-
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
62+
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
4563
github.com/go-errors/errors v1.4.2 // indirect
64+
github.com/go-gorp/gorp/v3 v3.1.0 // indirect
4665
github.com/go-logr/logr v1.4.2 // indirect
4766
github.com/go-logr/stdr v1.2.2 // indirect
4867
github.com/go-openapi/jsonpointer v0.21.0 // indirect
4968
github.com/go-openapi/jsonreference v0.21.0 // indirect
5069
github.com/go-openapi/swag v0.23.0 // indirect
70+
github.com/gobwas/glob v0.2.3 // indirect
5171
github.com/gogo/protobuf v1.3.2 // indirect
52-
github.com/golang/protobuf v1.5.4 // indirect
5372
github.com/google/btree v1.1.3 // indirect
54-
github.com/google/cel-go v0.23.2 // indirect
55-
github.com/google/gnostic-models v0.6.9 // indirect
73+
github.com/google/gnostic-models v0.7.0 // indirect
5674
github.com/google/go-cmp v0.7.0 // indirect
57-
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
5875
github.com/google/uuid v1.6.0 // indirect
76+
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 // indirect
77+
github.com/gosuri/uitable v0.0.4 // indirect
5978
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
60-
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
61-
github.com/grpc-ecosystem/grpc-gateway/v2 v2.25.1 // indirect
79+
github.com/hashicorp/errwrap v1.1.0 // indirect
80+
github.com/hashicorp/go-multierror v1.1.1 // indirect
81+
github.com/huandu/xstrings v1.5.0 // indirect
6282
github.com/inconshreveable/mousetrap v1.1.0 // indirect
83+
github.com/jmoiron/sqlx v1.4.0 // indirect
6384
github.com/josharian/intern v1.0.0 // indirect
6485
github.com/json-iterator/go v1.1.12 // indirect
65-
github.com/kylelemons/godebug v1.1.0 // indirect
86+
github.com/klauspost/compress v1.18.0 // indirect
87+
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
88+
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
89+
github.com/lib/pq v1.10.9 // indirect
6690
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
6791
github.com/mailru/easyjson v0.9.0 // indirect
6892
github.com/mattn/go-colorable v0.1.13 // indirect
6993
github.com/mattn/go-isatty v0.0.20 // indirect
7094
github.com/mattn/go-runewidth v0.0.12 // indirect
71-
github.com/moby/term v0.5.0 // indirect
95+
github.com/mitchellh/copystructure v1.2.0 // indirect
96+
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
97+
github.com/mitchellh/reflectwalk v1.0.2 // indirect
98+
github.com/moby/docker-image-spec v1.3.1 // indirect
99+
github.com/moby/spdystream v0.5.0 // indirect
100+
github.com/moby/sys/atomicwriter v0.1.0 // indirect
101+
github.com/moby/term v0.5.2 // indirect
72102
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
73-
github.com/modern-go/reflect2 v1.0.2 // indirect
103+
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
74104
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
105+
github.com/morikuni/aec v1.0.0 // indirect
75106
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
107+
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
76108
github.com/onsi/gomega v1.36.2 // indirect
109+
github.com/opencontainers/go-digest v1.0.0 // indirect
110+
github.com/opencontainers/image-spec v1.1.1 // indirect
111+
github.com/pelletier/go-toml v1.9.5 // indirect
77112
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
78113
github.com/pkg/errors v0.9.1 // indirect
79114
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
@@ -82,47 +117,44 @@ require (
82117
github.com/prometheus/common v0.62.0 // indirect
83118
github.com/prometheus/procfs v0.15.1 // indirect
84119
github.com/rivo/uniseg v0.2.0 // indirect
85-
github.com/stoewer/go-strcase v1.3.0 // indirect
120+
github.com/rubenv/sql-migrate v1.8.0 // indirect
121+
github.com/russross/blackfriday/v2 v2.1.0 // indirect
122+
github.com/santhosh-tekuri/jsonschema/v6 v6.0.2 // indirect
123+
github.com/shopspring/decimal v1.4.0 // indirect
124+
github.com/sirupsen/logrus v1.9.3 // indirect
125+
github.com/spf13/cast v1.7.0 // indirect
86126
github.com/x448/float16 v0.8.4 // indirect
87127
github.com/xlab/treeprint v1.2.0 // indirect
88-
go.etcd.io/etcd/api/v3 v3.5.21 // indirect
89-
go.etcd.io/etcd/client/pkg/v3 v3.5.21 // indirect
90-
go.etcd.io/etcd/client/v3 v3.5.21 // indirect
91128
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
92-
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.58.0 // indirect
93129
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.58.0 // indirect
94-
go.opentelemetry.io/otel v1.33.0 // indirect
95-
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.33.0 // indirect
96-
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.33.0 // indirect
97-
go.opentelemetry.io/otel/metric v1.33.0 // indirect
98-
go.opentelemetry.io/otel/sdk v1.33.0 // indirect
99-
go.opentelemetry.io/otel/trace v1.33.0 // indirect
100-
go.opentelemetry.io/proto/otlp v1.5.0 // indirect
101-
go.uber.org/multierr v1.11.0 // indirect
102-
go.uber.org/zap v1.27.0 // indirect
103-
golang.org/x/crypto v0.38.0 // indirect
104-
golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0 // indirect
105-
golang.org/x/net v0.40.0 // indirect
106-
golang.org/x/oauth2 v0.29.0 // indirect
107-
golang.org/x/sync v0.14.0 // indirect
108-
golang.org/x/sys v0.33.0 // indirect
109-
golang.org/x/term v0.32.0 // indirect
110-
golang.org/x/text v0.25.0 // indirect
111-
golang.org/x/time v0.11.0 // indirect
112-
google.golang.org/genproto/googleapis/api v0.0.0-20250106144421-5f5ef82da422 // indirect
113-
google.golang.org/genproto/googleapis/rpc v0.0.0-20250106144421-5f5ef82da422 // indirect
114-
google.golang.org/grpc v1.70.0 // indirect
130+
go.opentelemetry.io/otel v1.35.0 // indirect
131+
go.opentelemetry.io/otel/metric v1.35.0 // indirect
132+
go.opentelemetry.io/otel/trace v1.35.0 // indirect
133+
go.yaml.in/yaml/v2 v2.4.2 // indirect
134+
go.yaml.in/yaml/v3 v3.0.4 // indirect
135+
golang.org/x/crypto v0.41.0 // indirect
136+
golang.org/x/net v0.42.0 // indirect
137+
golang.org/x/oauth2 v0.30.0 // indirect
138+
golang.org/x/sync v0.16.0 // indirect
139+
golang.org/x/sys v0.35.0 // indirect
140+
golang.org/x/term v0.34.0 // indirect
141+
golang.org/x/text v0.28.0 // indirect
142+
golang.org/x/time v0.12.0 // indirect
143+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250303144028-a0af3efb3deb // indirect
144+
google.golang.org/grpc v1.72.1 // indirect
115145
google.golang.org/protobuf v1.36.5 // indirect
116146
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
117147
gopkg.in/inf.v0 v0.9.1 // indirect
118148
gopkg.in/yaml.v3 v3.0.1 // indirect
119-
k8s.io/apiserver v0.33.3 // indirect
120-
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect
149+
gotest.tools/v3 v3.5.2 // indirect
150+
k8s.io/apiserver v0.34.0 // indirect
151+
k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b // indirect
152+
k8s.io/kubectl v0.34.0 // indirect
121153
k8s.io/utils v0.0.0-20250604170112-4c0f3b243397 // indirect
122-
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.2 // indirect
154+
oras.land/oras-go/v2 v2.6.0 // indirect
123155
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
124-
sigs.k8s.io/kustomize/api v0.19.0 // indirect
125-
sigs.k8s.io/kustomize/kyaml v0.19.0 // indirect
156+
sigs.k8s.io/kustomize/api v0.20.1 // indirect
157+
sigs.k8s.io/kustomize/kyaml v0.20.1 // indirect
126158
sigs.k8s.io/randfill v1.0.0 // indirect
127-
sigs.k8s.io/structured-merge-diff/v4 v4.6.0 // indirect
159+
sigs.k8s.io/structured-merge-diff/v6 v6.3.0 // indirect
128160
)

0 commit comments

Comments
 (0)