Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
db006d6e
Commit
db006d6e
authored
Jul 05, 2016
by
Cole Mickens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix serviceaccount's usage of jwt-go
update pkg/serviceaccount for v3.x jwt-go.
parent
49d58367
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
12 deletions
+16
-12
jwt.go
pkg/serviceaccount/jwt.go
+16
-12
No files found.
pkg/serviceaccount/jwt.go
View file @
db006d6e
...
...
@@ -92,17 +92,19 @@ type jwtTokenGenerator struct {
func
(
j
*
jwtTokenGenerator
)
GenerateToken
(
serviceAccount
api
.
ServiceAccount
,
secret
api
.
Secret
)
(
string
,
error
)
{
token
:=
jwt
.
New
(
jwt
.
SigningMethodRS256
)
claims
,
_
:=
token
.
Claims
.
(
jwt
.
MapClaims
)
// Identify the issuer
token
.
C
laims
[
IssuerClaim
]
=
Issuer
c
laims
[
IssuerClaim
]
=
Issuer
// Username
token
.
C
laims
[
SubjectClaim
]
=
MakeUsername
(
serviceAccount
.
Namespace
,
serviceAccount
.
Name
)
c
laims
[
SubjectClaim
]
=
MakeUsername
(
serviceAccount
.
Namespace
,
serviceAccount
.
Name
)
// Persist enough structured info for the authenticator to be able to look up the service account and secret
token
.
C
laims
[
NamespaceClaim
]
=
serviceAccount
.
Namespace
token
.
C
laims
[
ServiceAccountNameClaim
]
=
serviceAccount
.
Name
token
.
C
laims
[
ServiceAccountUIDClaim
]
=
serviceAccount
.
UID
token
.
C
laims
[
SecretNameClaim
]
=
secret
.
Name
c
laims
[
NamespaceClaim
]
=
serviceAccount
.
Namespace
c
laims
[
ServiceAccountNameClaim
]
=
serviceAccount
.
Name
c
laims
[
ServiceAccountUIDClaim
]
=
serviceAccount
.
UID
c
laims
[
SecretNameClaim
]
=
secret
.
Name
// Sign and get the complete encoded token as a string
return
token
.
SignedString
(
j
.
key
)
...
...
@@ -133,6 +135,8 @@ func (j *jwtTokenAuthenticator) AuthenticateToken(token string) (user.Info, bool
return
key
,
nil
})
claims
,
_
:=
parsedToken
.
Claims
.
(
jwt
.
MapClaims
)
if
err
!=
nil
{
switch
err
:=
err
.
(
type
)
{
case
*
jwt
.
ValidationError
:
...
...
@@ -157,29 +161,29 @@ func (j *jwtTokenAuthenticator) AuthenticateToken(token string) (user.Info, bool
// If we get here, we have a token with a recognized signature
// Make sure we issued the token
iss
,
_
:=
parsedToken
.
C
laims
[
IssuerClaim
]
.
(
string
)
iss
,
_
:=
c
laims
[
IssuerClaim
]
.
(
string
)
if
iss
!=
Issuer
{
return
nil
,
false
,
nil
}
// Make sure the claims we need exist
sub
,
_
:=
parsedToken
.
C
laims
[
SubjectClaim
]
.
(
string
)
sub
,
_
:=
c
laims
[
SubjectClaim
]
.
(
string
)
if
len
(
sub
)
==
0
{
return
nil
,
false
,
errors
.
New
(
"sub claim is missing"
)
}
namespace
,
_
:=
parsedToken
.
C
laims
[
NamespaceClaim
]
.
(
string
)
namespace
,
_
:=
c
laims
[
NamespaceClaim
]
.
(
string
)
if
len
(
namespace
)
==
0
{
return
nil
,
false
,
errors
.
New
(
"namespace claim is missing"
)
}
secretName
,
_
:=
parsedToken
.
C
laims
[
SecretNameClaim
]
.
(
string
)
secretName
,
_
:=
c
laims
[
SecretNameClaim
]
.
(
string
)
if
len
(
namespace
)
==
0
{
return
nil
,
false
,
errors
.
New
(
"secretName claim is missing"
)
}
serviceAccountName
,
_
:=
parsedToken
.
C
laims
[
ServiceAccountNameClaim
]
.
(
string
)
serviceAccountName
,
_
:=
c
laims
[
ServiceAccountNameClaim
]
.
(
string
)
if
len
(
serviceAccountName
)
==
0
{
return
nil
,
false
,
errors
.
New
(
"serviceAccountName claim is missing"
)
}
serviceAccountUID
,
_
:=
parsedToken
.
C
laims
[
ServiceAccountUIDClaim
]
.
(
string
)
serviceAccountUID
,
_
:=
c
laims
[
ServiceAccountUIDClaim
]
.
(
string
)
if
len
(
serviceAccountUID
)
==
0
{
return
nil
,
false
,
errors
.
New
(
"serviceAccountUID claim is missing"
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment