Skip to content

Commit 667783a

Browse files
authored
Embedded OIDC for quickstart & add bind dev cli preview command (#368)
* Add embedded oidc provider for quick start Signed-off-by: Mangirdas Judeikis <mangirdas@judeikis.lt> On-behalf-of: @SAP mangirdas.judeikis@sap.com * Add bind dev command and updage golang to fix linter Signed-off-by: Mangirdas Judeikis <mangirdas@judeikis.lt> On-behalf-of: @SAP mangirdas.judeikis@sap.com * add oidc docs Signed-off-by: Mangirdas Judeikis <mangirdas@judeikis.lt> On-behalf-of: @SAP mangirdas.judeikis@sap.com * address reviews --------- Signed-off-by: Mangirdas Judeikis <mangirdas@judeikis.lt>
1 parent f1cbbdb commit 667783a

59 files changed

Lines changed: 3356 additions & 976 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- uses: actions/checkout@v4
3131
- uses: actions/setup-go@v5
3232
with:
33-
go-version: v1.24.0
33+
go-version: v1.25.4
3434
- uses: actions/setup-node@v4
3535
with:
3636
node-version: '20'
@@ -45,7 +45,7 @@ jobs:
4545
- uses: actions/checkout@v4
4646
- uses: actions/setup-go@v5
4747
with:
48-
go-version: v1.24.0
48+
go-version: v1.25.4
4949
- uses: actions/setup-node@v4
5050
with:
5151
node-version: '20'
@@ -60,7 +60,7 @@ jobs:
6060
- uses: actions/checkout@v4
6161
- uses: actions/setup-go@v5
6262
with:
63-
go-version: v1.24.0
63+
go-version: v1.25.4
6464
- run: make test
6565

6666
lint:
@@ -70,7 +70,7 @@ jobs:
7070
- uses: actions/checkout@v4
7171
- uses: actions/setup-go@v5
7272
with:
73-
go-version: v1.24.0
73+
go-version: v1.25.4
7474
- run: make lint
7575

7676
verify:
@@ -80,5 +80,5 @@ jobs:
8080
- uses: actions/checkout@v4
8181
- uses: actions/setup-go@v5
8282
with:
83-
go-version: v1.24.0
83+
go-version: v1.25.4
8484
- run: make verify

.github/workflows/docs-gen-and-push.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434

3535
- uses: actions/setup-go@v5
3636
with:
37-
go-version: v1.24.0
37+
go-version: v1.25.4
3838
cache: true
3939

4040
- uses: actions/setup-python@v5

.github/workflows/goreleaser.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
fetch-depth: 0
2323
- uses: actions/setup-go@v5
2424
with:
25-
go-version: v1.24.0
25+
go-version: v1.25.4
2626
- name: Delete non-semver tags
2727
run: 'git tag -d $(git tag -l | grep -v "^v")'
2828
- name: Run GoReleaser on tag

.github/workflows/image.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- uses: actions/checkout@v4
2020
- uses: actions/setup-go@v5
2121
with:
22-
go-version: v1.24.0
22+
go-version: v1.25.4
2323
check-latest: true
2424

2525
# We need this to remove local tags that are not semver so goreleaser doesn't get confused.

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ apiserviceexport.yaml
2020
# Frontend dependencies and build
2121
web/node_modules/
2222
web/.vite/
23-
web/*.tsbuildinfo
23+
web/*.tsbuildinfo
24+
go.work
25+
go.work.sum

.ko.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
baseImageOverrides:
2-
github.com/google/ko: golang:1.24.0
2+
github.com/google/ko: golang:1.25.4
33

44
builds:
55
- id: konnector

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ ENV VITE_BUILD_TARGET=docker
3939
RUN npm run build
4040

4141
# Build Go binary with embedded UI assets
42-
FROM golang:1.24.0 AS go-build-env
42+
FROM golang:1.25.4 AS go-build-env
4343
WORKDIR /app
4444

4545
# Accept build arguments for multi-arch support

Dockerfile.konnector

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
FROM golang:1.24.0 AS builder
15+
FROM golang:1.25.4 AS builder
1616
WORKDIR /app
1717

1818
# Accept build arguments for multi-arch support

Makefile

Lines changed: 1 addition & 6 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

@@ -364,7 +359,7 @@ verify-modules: modules # Verify go modules are up to date
364359
done
365360

366361
.PHONY: verify
367-
verify: verify-modules verify-go-versions verify-imports verify-codegen verify-boilerplate ## verify formal properties of the code
362+
verify: verify-go-versions verify-imports verify-codegen verify-boilerplate ## verify formal properties of the code
368363

369364
.PHONY: help
370365
help: ## Show this help

backend/auth/handler.go

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package auth
1818

1919
import (
20+
"context"
2021
"encoding/base64"
2122
"encoding/json"
2223
"errors"
@@ -34,14 +35,23 @@ import (
3435
"github.com/kube-bind/kube-bind/backend/session"
3536
)
3637

38+
type OIDCProvider interface {
39+
GetOIDCProvider(ctx context.Context) (*OIDCServiceProvider, error)
40+
}
41+
42+
type AuthHandlerInterface interface {
43+
HandleAuthorize(w http.ResponseWriter, r *http.Request)
44+
HandleCallback(w http.ResponseWriter, r *http.Request)
45+
}
46+
3747
type AuthHandler struct {
38-
oidc *OIDCServiceProvider
48+
oidc OIDCProvider
3949
jwtService *JWTService
4050
cookieSigningKey []byte
4151
cookieEncryptionKey []byte
4252
}
4353

44-
func NewAuthHandler(oidc *OIDCServiceProvider, jwtService *JWTService, cookieSigningKey, cookieEncryptionKey []byte) *AuthHandler {
54+
func NewAuthHandler(oidc OIDCProvider, jwtService *JWTService, cookieSigningKey, cookieEncryptionKey []byte) *AuthHandler {
4555
return &AuthHandler{
4656
oidc: oidc,
4757
jwtService: jwtService,
@@ -85,8 +95,15 @@ func (ah *AuthHandler) HandleAuthorize(w http.ResponseWriter, r *http.Request) {
8595
return
8696
}
8797

98+
provider, err := ah.oidc.GetOIDCProvider(r.Context())
99+
if err != nil {
100+
logger.Info("failed to get OIDC provider", "error", err)
101+
ah.respondWithError(w, authReq.ClientType, err.Error(), http.StatusInternalServerError)
102+
return
103+
}
104+
88105
encoded := base64.URLEncoding.EncodeToString(dataCode)
89-
authURL := ah.oidc.OIDCProviderConfig(scopes).AuthCodeURL(encoded)
106+
authURL := provider.OIDCProviderConfig(scopes).AuthCodeURL(encoded)
90107

91108
http.Redirect(w, r, authURL, http.StatusFound)
92109
}
@@ -133,7 +150,25 @@ func (ah *AuthHandler) HandleCallback(w http.ResponseWriter, r *http.Request) {
133150
return
134151
}
135152

136-
token, err := ah.oidc.OIDCProviderConfig(nil).Exchange(r.Context(), code)
153+
provider, err := ah.oidc.GetOIDCProvider(r.Context())
154+
if err != nil {
155+
logger.Info("failed to get OIDC provider", "error", err)
156+
ah.respondWithError(w, authCode.ClientType, err.Error(), http.StatusInternalServerError)
157+
return
158+
}
159+
160+
// Create context with custom HTTP client if TLS config is available
161+
ctx := r.Context()
162+
if tlsConfig := provider.GetTLSConfig(); tlsConfig != nil {
163+
client := &http.Client{
164+
Transport: &http.Transport{
165+
TLSClientConfig: tlsConfig,
166+
},
167+
}
168+
ctx = context.WithValue(ctx, oauth2.HTTPClient, client)
169+
}
170+
171+
token, err := provider.OIDCProviderConfig(nil).Exchange(ctx, code)
137172
if err != nil {
138173
logger.Error(err, "failed to exchange token")
139174
http.Error(w, "internal error", http.StatusInternalServerError)

0 commit comments

Comments
 (0)