Skip to content

Commit ae47017

Browse files
committed
Added pod probes
1 parent 6ec749c commit ae47017

Some content is hidden

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

43 files changed

+2424
-20
lines changed

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ update-vendor:
7979
k8s.io/apiextensions-apiserver \
8080
github.com/cenkalti/backoff \
8181
github.com/dchest/uniuri \
82+
github.com/dgrijalva/jwt-go \
8283
github.com/pkg/errors \
8384
github.com/prometheus/client_golang/prometheus \
8485
github.com/pulcy/pulsar \
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
language: go
22

3+
script:
4+
- go vet ./...
5+
- go test -v ./...
6+
37
go:
48
- 1.3
59
- 1.4
610
- 1.5
711
- 1.6
12+
- 1.7
813
- tip

deps/github.com/dgrijalva/jwt-go/MIGRATION_GUIDE.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ This simple parsing example:
5656
is directly mapped to:
5757

5858
```go
59-
if token, err := request.ParseFromRequest(tokenString, request.OAuth2Extractor, req, keyLookupFunc); err == nil {
60-
fmt.Printf("Token for user %v expires %v", token.Claims["user"], token.Claims["exp"])
59+
if token, err := request.ParseFromRequest(req, request.OAuth2Extractor, keyLookupFunc); err == nil {
60+
claims := token.Claims.(jwt.MapClaims)
61+
fmt.Printf("Token for user %v expires %v", claims["user"], claims["exp"])
6162
}
6263
```
6364

deps/github.com/dgrijalva/jwt-go/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ A [go](http://www.golang.org) (or 'golang' for search engine friendliness) imple
44

55
**BREAKING CHANGES:*** Version 3.0.0 is here. It includes _a lot_ of changes including a few that break the API. We've tried to break as few things as possible, so there should just be a few type signature changes. A full list of breaking changes is available in `VERSION_HISTORY.md`. See `MIGRATION_GUIDE.md` for more information on updating your code.
66

7-
**NOTICE:** A vulnerability in JWT was [recently published](https://auth0.com/blog/2015/03/31/critical-vulnerabilities-in-json-web-token-libraries/). As this library doesn't force users to validate the `alg` is what they expected, it's possible your usage is effected. There will be an update soon to remedy this, and it will likey require backwards-incompatible changes to the API. In the short term, please make sure your implementation verifies the `alg` is what you expect.
7+
**NOTICE:** It's important that you [validate the `alg` presented is what you expect](https://auth0.com/blog/2015/03/31/critical-vulnerabilities-in-json-web-token-libraries/). This library attempts to make it easy to do the right thing by requiring key types match the expected alg, but you should take the extra step to verify it in your usage. See the examples provided.
88

99

1010
## What the heck is a JWT?
@@ -74,12 +74,12 @@ It's worth mentioning that OAuth and JWT are not the same thing. A JWT token is
7474

7575
Without going too far down the rabbit hole, here's a description of the interaction of these technologies:
7676

77-
* OAuth is a protocol for allowing an identity provider to be separate from the service a user is logging in to. For example, whenever you use Facebook to log into a different service (Yelp, Spotify, etc), you are using OAuth.
77+
* OAuth is a protocol for allowing an identity provider to be separate from the service a user is logging in to. For example, whenever you use Facebook to log into a different service (Yelp, Spotify, etc), you are using OAuth.
7878
* OAuth defines several options for passing around authentication data. One popular method is called a "bearer token". A bearer token is simply a string that _should_ only be held by an authenticated user. Thus, simply presenting this token proves your identity. You can probably derive from here why a JWT might make a good bearer token.
7979
* Because bearer tokens are used for authentication, it's important they're kept secret. This is why transactions that use bearer tokens typically happen over SSL.
8080

8181
## More
8282

8383
Documentation can be found [on godoc.org](http://godoc.org/github.com/dgrijalva/jwt-go).
8484

85-
The command line utility included in this project (cmd/jwt) provides a straightforward example of token creation and parsing as well as a useful tool for debugging your own integration. You'll also find several implementation examples in to documentation.
85+
The command line utility included in this project (cmd/jwt) provides a straightforward example of token creation and parsing as well as a useful tool for debugging your own integration. You'll also find several implementation examples in the documentation.

deps/github.com/dgrijalva/jwt-go/VERSION_HISTORY.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
## `jwt-go` Version History
22

3+
#### 3.1.0
4+
5+
* Improvements to `jwt` command line tool
6+
* Added `SkipClaimsValidation` option to `Parser`
7+
* Documentation updates
8+
39
#### 3.0.0
410

511
* **Compatibility Breaking Changes**: See MIGRATION_GUIDE.md for tips on updating your code
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
`jwt` command-line tool
2+
=======================
3+
4+
This is a simple tool to sign, verify and show JSON Web Tokens from
5+
the command line.
6+
7+
The following will create and sign a token, then verify it and output the original claims:
8+
9+
echo {\"foo\":\"bar\"} | ./jwt -key ../../test/sample_key -alg RS256 -sign - | ./jwt -key ../../test/sample_key.pub -alg RS256 -verify -
10+
11+
To simply display a token, use:
12+
13+
echo $JWT | ./jwt -show -
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,282 @@
1+
// A useful example app. You can use this to debug your tokens on the command line.
2+
// This is also a great place to look at how you might use this library.
3+
//
4+
// Example usage:
5+
// The following will create and sign a token, then verify it and output the original claims.
6+
// echo {\"foo\":\"bar\"} | bin/jwt -key test/sample_key -alg RS256 -sign - | bin/jwt -key test/sample_key.pub -verify -
7+
package main
8+
9+
import (
10+
"encoding/json"
11+
"flag"
12+
"fmt"
13+
"io"
14+
"io/ioutil"
15+
"os"
16+
"regexp"
17+
"strings"
18+
19+
jwt "github.com/dgrijalva/jwt-go"
20+
)
21+
22+
var (
23+
// Options
24+
flagAlg = flag.String("alg", "", "signing algorithm identifier")
25+
flagKey = flag.String("key", "", "path to key file or '-' to read from stdin")
26+
flagCompact = flag.Bool("compact", false, "output compact JSON")
27+
flagDebug = flag.Bool("debug", false, "print out all kinds of debug data")
28+
flagClaims = make(ArgList)
29+
flagHead = make(ArgList)
30+
31+
// Modes - exactly one of these is required
32+
flagSign = flag.String("sign", "", "path to claims object to sign, '-' to read from stdin, or '+' to use only -claim args")
33+
flagVerify = flag.String("verify", "", "path to JWT token to verify or '-' to read from stdin")
34+
flagShow = flag.String("show", "", "path to JWT file or '-' to read from stdin")
35+
)
36+
37+
func main() {
38+
// Plug in Var flags
39+
flag.Var(flagClaims, "claim", "add additional claims. may be used more than once")
40+
flag.Var(flagHead, "header", "add additional header params. may be used more than once")
41+
42+
// Usage message if you ask for -help or if you mess up inputs.
43+
flag.Usage = func() {
44+
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
45+
fmt.Fprintf(os.Stderr, " One of the following flags is required: sign, verify\n")
46+
flag.PrintDefaults()
47+
}
48+
49+
// Parse command line options
50+
flag.Parse()
51+
52+
// Do the thing. If something goes wrong, print error to stderr
53+
// and exit with a non-zero status code
54+
if err := start(); err != nil {
55+
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
56+
os.Exit(1)
57+
}
58+
}
59+
60+
// Figure out which thing to do and then do that
61+
func start() error {
62+
if *flagSign != "" {
63+
return signToken()
64+
} else if *flagVerify != "" {
65+
return verifyToken()
66+
} else if *flagShow != "" {
67+
return showToken()
68+
} else {
69+
flag.Usage()
70+
return fmt.Errorf("None of the required flags are present. What do you want me to do?")
71+
}
72+
}
73+
74+
// Helper func: Read input from specified file or stdin
75+
func loadData(p string) ([]byte, error) {
76+
if p == "" {
77+
return nil, fmt.Errorf("No path specified")
78+
}
79+
80+
var rdr io.Reader
81+
if p == "-" {
82+
rdr = os.Stdin
83+
} else if p == "+" {
84+
return []byte("{}"), nil
85+
} else {
86+
if f, err := os.Open(p); err == nil {
87+
rdr = f
88+
defer f.Close()
89+
} else {
90+
return nil, err
91+
}
92+
}
93+
return ioutil.ReadAll(rdr)
94+
}
95+
96+
// Print a json object in accordance with the prophecy (or the command line options)
97+
func printJSON(j interface{}) error {
98+
var out []byte
99+
var err error
100+
101+
if *flagCompact == false {
102+
out, err = json.MarshalIndent(j, "", " ")
103+
} else {
104+
out, err = json.Marshal(j)
105+
}
106+
107+
if err == nil {
108+
fmt.Println(string(out))
109+
}
110+
111+
return err
112+
}
113+
114+
// Verify a token and output the claims. This is a great example
115+
// of how to verify and view a token.
116+
func verifyToken() error {
117+
// get the token
118+
tokData, err := loadData(*flagVerify)
119+
if err != nil {
120+
return fmt.Errorf("Couldn't read token: %v", err)
121+
}
122+
123+
// trim possible whitespace from token
124+
tokData = regexp.MustCompile(`\s*$`).ReplaceAll(tokData, []byte{})
125+
if *flagDebug {
126+
fmt.Fprintf(os.Stderr, "Token len: %v bytes\n", len(tokData))
127+
}
128+
129+
// Parse the token. Load the key from command line option
130+
token, err := jwt.Parse(string(tokData), func(t *jwt.Token) (interface{}, error) {
131+
data, err := loadData(*flagKey)
132+
if err != nil {
133+
return nil, err
134+
}
135+
if isEs() {
136+
return jwt.ParseECPublicKeyFromPEM(data)
137+
} else if isRs() {
138+
return jwt.ParseRSAPublicKeyFromPEM(data)
139+
}
140+
return data, nil
141+
})
142+
143+
// Print some debug data
144+
if *flagDebug && token != nil {
145+
fmt.Fprintf(os.Stderr, "Header:\n%v\n", token.Header)
146+
fmt.Fprintf(os.Stderr, "Claims:\n%v\n", token.Claims)
147+
}
148+
149+
// Print an error if we can't parse for some reason
150+
if err != nil {
151+
return fmt.Errorf("Couldn't parse token: %v", err)
152+
}
153+
154+
// Is token invalid?
155+
if !token.Valid {
156+
return fmt.Errorf("Token is invalid")
157+
}
158+
159+
// Print the token details
160+
if err := printJSON(token.Claims); err != nil {
161+
return fmt.Errorf("Failed to output claims: %v", err)
162+
}
163+
164+
return nil
165+
}
166+
167+
// Create, sign, and output a token. This is a great, simple example of
168+
// how to use this library to create and sign a token.
169+
func signToken() error {
170+
// get the token data from command line arguments
171+
tokData, err := loadData(*flagSign)
172+
if err != nil {
173+
return fmt.Errorf("Couldn't read token: %v", err)
174+
} else if *flagDebug {
175+
fmt.Fprintf(os.Stderr, "Token: %v bytes", len(tokData))
176+
}
177+
178+
// parse the JSON of the claims
179+
var claims jwt.MapClaims
180+
if err := json.Unmarshal(tokData, &claims); err != nil {
181+
return fmt.Errorf("Couldn't parse claims JSON: %v", err)
182+
}
183+
184+
// add command line claims
185+
if len(flagClaims) > 0 {
186+
for k, v := range flagClaims {
187+
claims[k] = v
188+
}
189+
}
190+
191+
// get the key
192+
var key interface{}
193+
key, err = loadData(*flagKey)
194+
if err != nil {
195+
return fmt.Errorf("Couldn't read key: %v", err)
196+
}
197+
198+
// get the signing alg
199+
alg := jwt.GetSigningMethod(*flagAlg)
200+
if alg == nil {
201+
return fmt.Errorf("Couldn't find signing method: %v", *flagAlg)
202+
}
203+
204+
// create a new token
205+
token := jwt.NewWithClaims(alg, claims)
206+
207+
// add command line headers
208+
if len(flagHead) > 0 {
209+
for k, v := range flagHead {
210+
token.Header[k] = v
211+
}
212+
}
213+
214+
if isEs() {
215+
if k, ok := key.([]byte); !ok {
216+
return fmt.Errorf("Couldn't convert key data to key")
217+
} else {
218+
key, err = jwt.ParseECPrivateKeyFromPEM(k)
219+
if err != nil {
220+
return err
221+
}
222+
}
223+
} else if isRs() {
224+
if k, ok := key.([]byte); !ok {
225+
return fmt.Errorf("Couldn't convert key data to key")
226+
} else {
227+
key, err = jwt.ParseRSAPrivateKeyFromPEM(k)
228+
if err != nil {
229+
return err
230+
}
231+
}
232+
}
233+
234+
if out, err := token.SignedString(key); err == nil {
235+
fmt.Println(out)
236+
} else {
237+
return fmt.Errorf("Error signing token: %v", err)
238+
}
239+
240+
return nil
241+
}
242+
243+
// showToken pretty-prints the token on the command line.
244+
func showToken() error {
245+
// get the token
246+
tokData, err := loadData(*flagShow)
247+
if err != nil {
248+
return fmt.Errorf("Couldn't read token: %v", err)
249+
}
250+
251+
// trim possible whitespace from token
252+
tokData = regexp.MustCompile(`\s*$`).ReplaceAll(tokData, []byte{})
253+
if *flagDebug {
254+
fmt.Fprintf(os.Stderr, "Token len: %v bytes\n", len(tokData))
255+
}
256+
257+
token, err := jwt.Parse(string(tokData), nil)
258+
if token == nil {
259+
return fmt.Errorf("malformed token: %v", err)
260+
}
261+
262+
// Print the token details
263+
fmt.Println("Header:")
264+
if err := printJSON(token.Header); err != nil {
265+
return fmt.Errorf("Failed to output header: %v", err)
266+
}
267+
268+
fmt.Println("Claims:")
269+
if err := printJSON(token.Claims); err != nil {
270+
return fmt.Errorf("Failed to output claims: %v", err)
271+
}
272+
273+
return nil
274+
}
275+
276+
func isEs() bool {
277+
return strings.HasPrefix(*flagAlg, "ES")
278+
}
279+
280+
func isRs() bool {
281+
return strings.HasPrefix(*flagAlg, "RS")
282+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"strings"
7+
)
8+
9+
type ArgList map[string]string
10+
11+
func (l ArgList) String() string {
12+
data, _ := json.Marshal(l)
13+
return string(data)
14+
}
15+
16+
func (l ArgList) Set(arg string) error {
17+
parts := strings.SplitN(arg, "=", 2)
18+
if len(parts) != 2 {
19+
return fmt.Errorf("Invalid argument '%v'. Must use format 'key=value'. %v", arg, parts)
20+
}
21+
l[parts[0]] = parts[1]
22+
return nil
23+
}

0 commit comments

Comments
 (0)