Skip to content

Commit 7052943

Browse files
gauron99matejvasek
andauthored
[1.20] backport host auth and fix springboot template (#3301)
* Clean up auth for host builder (#3298) Signed-off-by: Matej Vašek <[email protected]> * springboot template fix * test upstream ci (#3200) --------- Signed-off-by: Matej Vašek <[email protected]> Co-authored-by: Matej Vašek <[email protected]>
1 parent c9d4c54 commit 7052943

File tree

15 files changed

+4463
-4538
lines changed

15 files changed

+4463
-4538
lines changed

.github/workflows/test-e2e-oncluster-runtime.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ jobs:
1212
func_builder: ["pack", "s2i"]
1313
runs-on: ${{ matrix.os }}
1414
steps:
15+
- name: Cleanup space
16+
run: |
17+
df -h
18+
sudo rm -rf /usr/local/lib/android
19+
sudo rm -rf /usr/share/dotnet
20+
sudo rm -rf /opt/ghc
21+
sudo rm -rf /opt/hostedtoolcache/CodeQL
22+
docker system prune -af
23+
df -h
1524
- name: Set Environment Variables
1625
run: |
1726
echo "KUBECONFIG=${{ github.workspace }}/hack/bin/kubeconfig.yaml" >> "$GITHUB_ENV"

.github/workflows/test-e2e-oncluster.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ jobs:
1010
os: ["ubuntu-latest"]
1111
runs-on: ${{ matrix.os }}
1212
steps:
13+
- name: Cleanup space
14+
run: |
15+
df -h
16+
sudo rm -rf /usr/local/lib/android
17+
sudo rm -rf /usr/share/dotnet
18+
sudo rm -rf /opt/ghc
19+
sudo rm -rf /opt/hostedtoolcache/CodeQL
20+
docker system prune -af
21+
df -h
1322
- name: Set Environment Variables
1423
run: |
1524
echo "KUBECONFIG=${{ github.workspace }}/hack/bin/kubeconfig.yaml" >> "$GITHUB_ENV"

.github/workflows/test-e2e-runtime.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ jobs:
2727
arch: arm64
2828
runs-on: ${{ matrix.os }}
2929
steps:
30+
- name: Cleanup space
31+
run: |
32+
df -h
33+
sudo rm -rf /usr/local/lib/android
34+
sudo rm -rf /usr/share/dotnet
35+
sudo rm -rf /opt/ghc
36+
sudo rm -rf /opt/hostedtoolcache/CodeQL
37+
docker system prune -af
38+
df -h
3039
- name: Set Environment Variables
3140
run: |
3241
echo "KUBECONFIG=${{ github.workspace }}/hack/bin/kubeconfig.yaml" >> "$GITHUB_ENV"

.github/workflows/test-e2e.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ jobs:
1010
os: ["ubuntu-latest"]
1111
runs-on: ${{ matrix.os }}
1212
steps:
13+
- name: Cleanup space
14+
run: |
15+
df -h
16+
sudo rm -rf /usr/local/lib/android
17+
sudo rm -rf /usr/share/dotnet
18+
sudo rm -rf /opt/ghc
19+
sudo rm -rf /opt/hostedtoolcache/CodeQL
20+
docker system prune -af
21+
df -h
1322
- name: Set Environment Variables
1423
run: |
1524
echo "KUBECONFIG=${{ github.workspace }}/hack/bin/kubeconfig.yaml" >> "$GITHUB_ENV"

cmd/build.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cmd
22

33
import (
4-
"context"
54
"errors"
65
"fmt"
76
"strings"
@@ -212,8 +211,6 @@ For more options, run 'func build --help'`, err)
212211
}
213212
f = cfg.Configure(f) // Returns an f updated with values from the config (flags, envs, etc)
214213

215-
cmd.SetContext(cfg.WithValues(cmd.Context())) // Some optional settings are passed via context
216-
217214
// Client
218215
clientOptions, err := cfg.clientOptions()
219216
if err != nil {
@@ -243,16 +240,6 @@ For more options, run 'func build --help'`, err)
243240
return f.Stamp()
244241
}
245242

246-
// WithValues returns a context populated with values from the build config
247-
// which are provided to the system via the context.
248-
func (c buildConfig) WithValues(ctx context.Context) context.Context {
249-
// Push
250-
ctx = context.WithValue(ctx, fn.PushUsernameKey{}, c.Username)
251-
ctx = context.WithValue(ctx, fn.PushPasswordKey{}, c.Password)
252-
ctx = context.WithValue(ctx, fn.PushTokenKey{}, c.Token)
253-
return ctx
254-
}
255-
256243
type buildConfig struct {
257244
// Globals (builder, confirm, registry, verbose)
258245
config.Global

cmd/build_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,6 @@ func TestBuild_RegistryOrImageRequired(t *testing.T) {
8989
testRegistryOrImageRequired(NewBuildCmd, t)
9090
}
9191

92-
// TestBuild_Authentication ensures that Token and Username/Password auth
93-
// propagate to pushers which support them.
94-
func TestBuild_Authentication(t *testing.T) {
95-
testAuthentication(NewBuildCmd, t)
96-
}
97-
9892
// TestBuild_BaseImage ensures that base image is used only with the right
9993
// builders and propagates into f.Build.BaseImage
10094
func TestBuild_BaseImage(t *testing.T) {

cmd/client.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"net/http"
66
"os"
77

8+
"github.com/ory/viper"
9+
810
"knative.dev/func/cmd/prompt"
911
"knative.dev/func/pkg/builders/buildpacks"
1012
"knative.dev/func/pkg/config"
@@ -105,6 +107,23 @@ func newCredentialsProvider(configPath string, t http.RoundTripper) oci.Credenti
105107
additionalLoaders := append(k8s.GetOpenShiftDockerCredentialLoaders(), k8s.GetGoogleCredentialLoader()...)
106108
additionalLoaders = append(additionalLoaders, k8s.GetECRCredentialLoader()...)
107109
additionalLoaders = append(additionalLoaders, k8s.GetACRCredentialLoader()...)
110+
111+
additionalLoaders = append(additionalLoaders,
112+
func(registry string) (oci.Credentials, error) {
113+
uname := viper.GetString("username")
114+
passw := viper.GetString("password")
115+
token := viper.GetString("token")
116+
if (uname != "" && passw != "") || token != "" {
117+
return oci.Credentials{
118+
Username: uname,
119+
Password: passw,
120+
Token: token,
121+
}, nil
122+
}
123+
return oci.Credentials{}, creds.ErrCredentialsNotFound
124+
},
125+
)
126+
108127
options := []creds.Opt{
109128
creds.WithPromptForCredentials(prompt.NewPromptForCredentials(os.Stdin, os.Stdout, os.Stderr)),
110129
creds.WithPromptForCredentialStore(prompt.NewPromptForCredentialStore()),

cmd/deploy.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@ For more options, run 'func deploy --help'`, err)
313313
if f, err = cfg.Configure(f); err != nil { // Updates f with deploy cfg
314314
return
315315
}
316-
cmd.SetContext(cfg.WithValues(cmd.Context())) // Some optional settings are passed via context
317316

318317
changingNamespace := func(f fn.Function) bool {
319318
// We're changing namespace if:

cmd/deploy_test.go

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,74 +1501,6 @@ func testRegistryOrImageRequired(cmdFn commandConstructor, t *testing.T) {
15011501
}
15021502
}
15031503

1504-
// TestDeploy_Authentication ensures that Token and Username/Password auth
1505-
// propagate their values to pushers which support them.
1506-
func TestDeploy_Authentication(t *testing.T) {
1507-
testAuthentication(NewDeployCmd, t)
1508-
}
1509-
1510-
func testAuthentication(cmdFn commandConstructor, t *testing.T) {
1511-
// This test is currently focused on ensuring the flags for
1512-
// explicit credentials (bearer token and username/password) are respected
1513-
// and propagated to pushers which support this authentication method.
1514-
// Integration tests must be used to ensure correct integration between
1515-
// the system and credential helpers (Docker, ecs, acs)
1516-
t.Helper()
1517-
1518-
root := FromTempDirectory(t)
1519-
_, err := fn.New().Init(fn.Function{Runtime: "go", Root: root, Registry: TestRegistry})
1520-
if err != nil {
1521-
t.Fatal(err)
1522-
}
1523-
1524-
var (
1525-
testUser = "alice"
1526-
testPass = "123"
1527-
testToken = "example.jwt.token"
1528-
)
1529-
1530-
// Basic Auth: username/password
1531-
// -----------------------------
1532-
pusher := mock.NewPusher()
1533-
pusher.PushFn = func(ctx context.Context, _ fn.Function) (string, error) {
1534-
username, _ := ctx.Value(fn.PushUsernameKey{}).(string)
1535-
password, _ := ctx.Value(fn.PushPasswordKey{}).(string)
1536-
1537-
if username != testUser || password != testPass {
1538-
t.Fatalf("expected username %q, password %q. Got %q, %q", testUser, testPass, username, password)
1539-
}
1540-
1541-
return "", nil
1542-
}
1543-
1544-
cmd := cmdFn(NewTestClient(fn.WithPusher(pusher)))
1545-
cmd.SetArgs([]string{"--builder", "host", "--username", testUser, "--password", testPass})
1546-
if err := cmd.Execute(); err != nil {
1547-
t.Fatal(err)
1548-
}
1549-
1550-
// Basic Auth: token
1551-
// -----------------------------
1552-
pusher = mock.NewPusher()
1553-
pusher.PushFn = func(ctx context.Context, _ fn.Function) (string, error) {
1554-
token, _ := ctx.Value(fn.PushTokenKey{}).(string)
1555-
1556-
if token != testToken {
1557-
t.Fatalf("expected token %q, got %q", testToken, token)
1558-
}
1559-
1560-
return "", nil
1561-
}
1562-
1563-
cmd = cmdFn(NewTestClient(fn.WithPusher(pusher)))
1564-
1565-
cmd.SetArgs([]string{"--builder", "host", "--token", testToken})
1566-
if err := cmd.Execute(); err != nil {
1567-
t.Fatal(err)
1568-
}
1569-
1570-
}
1571-
15721504
// TestDeploy_RemoteBuildURLPermutations ensures that the remote, build and git-url flags
15731505
// are properly respected for all permutations, including empty.
15741506
func TestDeploy_RemoteBuildURLPermutations(t *testing.T) {

0 commit comments

Comments
 (0)