-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a simple knative service for fetch oidc tokens off the cluster
for testing external access with fulcio as well. Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
- Loading branch information
Showing
10 changed files
with
130 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2022 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 main | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
|
||
"github.com/kelseyhightower/envconfig" | ||
) | ||
|
||
type envConfig struct { | ||
FileName string `envconfig:"OIDC_FILE" default:"/var/run/sigstore/cosign/oidc-token" required:"true"` | ||
} | ||
|
||
// tokenFile is where we mount the oidc token from k8s. | ||
//const tokenFile = "/var/run/sigstore/cosign/oidc-token" | ||
const tokenFile = "/Users/vaikas/projects/go/src/github.com/sigstore/scaffolding/ctlog-public.pem" | ||
|
||
func tokenWriter(filename string) func(http.ResponseWriter, *http.Request) { | ||
return func(w http.ResponseWriter, req *http.Request) { | ||
getToken(filename, w, req) | ||
} | ||
} | ||
func getToken(tokenFile string, w http.ResponseWriter, req *http.Request) { | ||
content, err := ioutil.ReadFile(tokenFile) | ||
if err != nil { | ||
log.Print("failed to read token file", err) | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
_, err = fmt.Fprint(w, string(content)) | ||
if err != nil { | ||
log.Print("failed to write token file to response", err) | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
} | ||
} | ||
|
||
func main() { | ||
var env envConfig | ||
if err := envconfig.Process("", &env); err != nil { | ||
log.Fatalf("failed to process env var: %s", err) | ||
} | ||
http.HandleFunc("/", tokenWriter(env.FileName)) | ||
if err := http.ListenAndServe(":8080", nil); err != nil { | ||
panic(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
apiVersion: serving.knative.dev/v1 | ||
kind: Service | ||
metadata: | ||
name: gettoken | ||
spec: | ||
template: | ||
spec: | ||
containers: | ||
- name: gettoken | ||
image: ko://github.com/sigstore/scaffolding/cmd/getoidctoken | ||
env: | ||
- name: OIDC_FILE | ||
value: "/var/run/sigstore/cosign/oidc-token" | ||
volumeMounts: | ||
- name: oidc-info | ||
mountPath: /var/run/sigstore/cosign | ||
volumes: | ||
- name: oidc-info | ||
projected: | ||
sources: | ||
- serviceAccountToken: | ||
path: oidc-token | ||
expirationSeconds: 600 | ||
audience: sigstore |
This file was deleted.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
third_party/VENDOR-LICENSE/github.com/kelseyhightower/envconfig/LICENSE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2013 Kelsey Hightower | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
of the Software, and to permit persons to whom the Software is furnished to do | ||
so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
27 changes: 0 additions & 27 deletions
27
third_party/VENDOR-LICENSE/vendor/golang.org/x/crypto/LICENSE
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
third_party/VENDOR-LICENSE/vendor/golang.org/x/net/LICENSE
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
third_party/VENDOR-LICENSE/vendor/golang.org/x/text/LICENSE
This file was deleted.
Oops, something went wrong.