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
198b9e48
Commit
198b9e48
authored
Apr 23, 2018
by
WanLinghao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix a error in serviceaccount validate.
This error is a human-writing error. Small as it is, it could cause recreate Object validate through bug. This patch fix it.
parent
a048ca88
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
4 deletions
+86
-4
claims.go
pkg/serviceaccount/claims.go
+4
-4
svcaccttoken_test.go
test/integration/auth/svcaccttoken_test.go
+82
-0
No files found.
pkg/serviceaccount/claims.go
View file @
198b9e48
...
@@ -155,8 +155,8 @@ func (v *validator) Validate(_ string, public *jwt.Claims, privateObj interface{
...
@@ -155,8 +155,8 @@ func (v *validator) Validate(_ string, public *jwt.Claims, privateObj interface{
glog
.
V
(
4
)
.
Infof
(
"Bound secret is deleted and awaiting removal: %s/%s for service account %s/%s"
,
namespace
,
secref
.
Name
,
namespace
,
saref
.
Name
)
glog
.
V
(
4
)
.
Infof
(
"Bound secret is deleted and awaiting removal: %s/%s for service account %s/%s"
,
namespace
,
secref
.
Name
,
namespace
,
saref
.
Name
)
return
""
,
""
,
""
,
errors
.
New
(
"Token has been invalidated"
)
return
""
,
""
,
""
,
errors
.
New
(
"Token has been invalidated"
)
}
}
if
s
tring
(
secref
.
UID
)
!=
secref
.
UID
{
if
s
ecref
.
UID
!=
string
(
secret
.
UID
)
{
glog
.
V
(
4
)
.
Infof
(
"Secret UID no longer matches %s/%s: %q != %q"
,
namespace
,
secref
.
Name
,
string
(
se
rviceAccoun
t
.
UID
),
secref
.
UID
)
glog
.
V
(
4
)
.
Infof
(
"Secret UID no longer matches %s/%s: %q != %q"
,
namespace
,
secref
.
Name
,
string
(
se
cre
t
.
UID
),
secref
.
UID
)
return
""
,
""
,
""
,
fmt
.
Errorf
(
"Secret UID (%s) does not match claim (%s)"
,
secret
.
UID
,
secref
.
UID
)
return
""
,
""
,
""
,
fmt
.
Errorf
(
"Secret UID (%s) does not match claim (%s)"
,
secret
.
UID
,
secref
.
UID
)
}
}
}
}
...
@@ -172,8 +172,8 @@ func (v *validator) Validate(_ string, public *jwt.Claims, privateObj interface{
...
@@ -172,8 +172,8 @@ func (v *validator) Validate(_ string, public *jwt.Claims, privateObj interface{
glog
.
V
(
4
)
.
Infof
(
"Bound pod is deleted and awaiting removal: %s/%s for service account %s/%s"
,
namespace
,
podref
.
Name
,
namespace
,
saref
.
Name
)
glog
.
V
(
4
)
.
Infof
(
"Bound pod is deleted and awaiting removal: %s/%s for service account %s/%s"
,
namespace
,
podref
.
Name
,
namespace
,
saref
.
Name
)
return
""
,
""
,
""
,
errors
.
New
(
"Token has been invalidated"
)
return
""
,
""
,
""
,
errors
.
New
(
"Token has been invalidated"
)
}
}
if
string
(
podref
.
UID
)
!=
podref
.
UID
{
if
podref
.
UID
!=
string
(
pod
.
UID
)
{
glog
.
V
(
4
)
.
Infof
(
"Pod UID no longer matches %s/%s: %q != %q"
,
namespace
,
podref
.
Name
,
string
(
serviceAccount
.
UID
),
podref
.
UID
)
glog
.
V
(
4
)
.
Infof
(
"Pod UID no longer matches %s/%s: %q != %q"
,
namespace
,
podref
.
Name
,
string
(
pod
.
UID
),
podref
.
UID
)
return
""
,
""
,
""
,
fmt
.
Errorf
(
"Pod UID (%s) does not match claim (%s)"
,
pod
.
UID
,
podref
.
UID
)
return
""
,
""
,
""
,
fmt
.
Errorf
(
"Pod UID (%s) does not match claim (%s)"
,
pod
.
UID
,
podref
.
UID
)
}
}
}
}
...
...
test/integration/auth/svcaccttoken_test.go
View file @
198b9e48
...
@@ -342,6 +342,88 @@ func TestServiceAccountTokenCreate(t *testing.T) {
...
@@ -342,6 +342,88 @@ func TestServiceAccountTokenCreate(t *testing.T) {
doTokenReview
(
t
,
cs
,
treq
,
false
)
doTokenReview
(
t
,
cs
,
treq
,
false
)
})
})
t
.
Run
(
"a token should be invalid after recreating same name pod"
,
func
(
t
*
testing
.
T
)
{
treq
:=
&
authenticationv1
.
TokenRequest
{
Spec
:
authenticationv1
.
TokenRequestSpec
{
Audiences
:
[]
string
{
"api"
},
ExpirationSeconds
:
&
one
,
BoundObjectRef
:
&
authenticationv1
.
BoundObjectReference
{
Kind
:
"Pod"
,
APIVersion
:
"v1"
,
Name
:
pod
.
Name
,
},
},
}
sa
,
del
:=
createDeleteSvcAcct
(
t
,
cs
,
sa
)
defer
del
()
originalPod
,
originalDelPod
:=
createDeletePod
(
t
,
cs
,
pod
)
defer
originalDelPod
()
treq
.
Spec
.
BoundObjectRef
.
UID
=
originalPod
.
UID
if
treq
,
err
=
cs
.
CoreV1
()
.
ServiceAccounts
(
sa
.
Namespace
)
.
CreateToken
(
sa
.
Name
,
treq
);
err
!=
nil
{
t
.
Fatalf
(
"err: %v"
,
err
)
}
checkPayload
(
t
,
treq
.
Status
.
Token
,
`"system:serviceaccount:myns:test-svcacct"`
,
"sub"
)
checkPayload
(
t
,
treq
.
Status
.
Token
,
`["api"]`
,
"aud"
)
checkPayload
(
t
,
treq
.
Status
.
Token
,
`"test-pod"`
,
"kubernetes.io"
,
"pod"
,
"name"
)
checkPayload
(
t
,
treq
.
Status
.
Token
,
"null"
,
"kubernetes.io"
,
"secret"
)
checkPayload
(
t
,
treq
.
Status
.
Token
,
`"myns"`
,
"kubernetes.io"
,
"namespace"
)
checkPayload
(
t
,
treq
.
Status
.
Token
,
`"test-svcacct"`
,
"kubernetes.io"
,
"serviceaccount"
,
"name"
)
doTokenReview
(
t
,
cs
,
treq
,
false
)
originalDelPod
()
doTokenReview
(
t
,
cs
,
treq
,
true
)
_
,
recreateDelPod
:=
createDeletePod
(
t
,
cs
,
pod
)
defer
recreateDelPod
()
doTokenReview
(
t
,
cs
,
treq
,
true
)
})
t
.
Run
(
"a token should be invalid after recreating same name secret"
,
func
(
t
*
testing
.
T
)
{
treq
:=
&
authenticationv1
.
TokenRequest
{
Spec
:
authenticationv1
.
TokenRequestSpec
{
Audiences
:
[]
string
{
"api"
},
ExpirationSeconds
:
&
one
,
BoundObjectRef
:
&
authenticationv1
.
BoundObjectReference
{
Kind
:
"Secret"
,
APIVersion
:
"v1"
,
Name
:
secret
.
Name
,
UID
:
secret
.
UID
,
},
},
}
sa
,
del
:=
createDeleteSvcAcct
(
t
,
cs
,
sa
)
defer
del
()
originalSecret
,
originalDelSecret
:=
createDeleteSecret
(
t
,
cs
,
secret
)
defer
originalDelSecret
()
treq
.
Spec
.
BoundObjectRef
.
UID
=
originalSecret
.
UID
if
treq
,
err
=
cs
.
CoreV1
()
.
ServiceAccounts
(
sa
.
Namespace
)
.
CreateToken
(
sa
.
Name
,
treq
);
err
!=
nil
{
t
.
Fatalf
(
"err: %v"
,
err
)
}
checkPayload
(
t
,
treq
.
Status
.
Token
,
`"system:serviceaccount:myns:test-svcacct"`
,
"sub"
)
checkPayload
(
t
,
treq
.
Status
.
Token
,
`["api"]`
,
"aud"
)
checkPayload
(
t
,
treq
.
Status
.
Token
,
`null`
,
"kubernetes.io"
,
"pod"
)
checkPayload
(
t
,
treq
.
Status
.
Token
,
`"test-secret"`
,
"kubernetes.io"
,
"secret"
,
"name"
)
checkPayload
(
t
,
treq
.
Status
.
Token
,
`"myns"`
,
"kubernetes.io"
,
"namespace"
)
checkPayload
(
t
,
treq
.
Status
.
Token
,
`"test-svcacct"`
,
"kubernetes.io"
,
"serviceaccount"
,
"name"
)
doTokenReview
(
t
,
cs
,
treq
,
false
)
originalDelSecret
()
doTokenReview
(
t
,
cs
,
treq
,
true
)
_
,
recreateDelSecret
:=
createDeleteSecret
(
t
,
cs
,
secret
)
defer
recreateDelSecret
()
doTokenReview
(
t
,
cs
,
treq
,
true
)
})
}
}
func
doTokenReview
(
t
*
testing
.
T
,
cs
externalclientset
.
Interface
,
treq
*
authenticationv1
.
TokenRequest
,
expectErr
bool
)
{
func
doTokenReview
(
t
*
testing
.
T
,
cs
externalclientset
.
Interface
,
treq
*
authenticationv1
.
TokenRequest
,
expectErr
bool
)
{
...
...
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