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
89c3fd52
Unverified
Commit
89c3fd52
authored
Oct 11, 2018
by
k8s-ci-robot
Committed by
GitHub
Oct 11, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #68632 from deads2k/server-06-audit
allow audit policy to be loaded from any byte source
parents
cdf264ca
5d46ff41
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
4 deletions
+13
-4
reader.go
staging/src/k8s.io/apiserver/pkg/audit/policy/reader.go
+13
-4
No files found.
staging/src/k8s.io/apiserver/pkg/audit/policy/reader.go
View file @
89c3fd52
...
@@ -55,17 +55,26 @@ func LoadPolicyFromFile(filePath string) (*auditinternal.Policy, error) {
...
@@ -55,17 +55,26 @@ func LoadPolicyFromFile(filePath string) (*auditinternal.Policy, error) {
return
nil
,
fmt
.
Errorf
(
"failed to read file path %q: %+v"
,
filePath
,
err
)
return
nil
,
fmt
.
Errorf
(
"failed to read file path %q: %+v"
,
filePath
,
err
)
}
}
ret
,
err
:=
LoadPolicyFromBytes
(
policyDef
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"%v: from file %v"
,
err
.
Error
(),
filePath
)
}
return
ret
,
nil
}
func
LoadPolicyFromBytes
(
policyDef
[]
byte
)
(
*
auditinternal
.
Policy
,
error
)
{
policy
:=
&
auditinternal
.
Policy
{}
policy
:=
&
auditinternal
.
Policy
{}
decoder
:=
audit
.
Codecs
.
UniversalDecoder
(
apiGroupVersions
...
)
decoder
:=
audit
.
Codecs
.
UniversalDecoder
(
apiGroupVersions
...
)
_
,
gvk
,
err
:=
decoder
.
Decode
(
policyDef
,
nil
,
policy
)
_
,
gvk
,
err
:=
decoder
.
Decode
(
policyDef
,
nil
,
policy
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed decoding
file %q: %v"
,
filePath
,
err
)
return
nil
,
fmt
.
Errorf
(
"failed decoding
: %v"
,
err
)
}
}
// Ensure the policy file contained an apiVersion and kind.
// Ensure the policy file contained an apiVersion and kind.
if
!
apiGroupVersionSet
[
schema
.
GroupVersion
{
Group
:
gvk
.
Group
,
Version
:
gvk
.
Version
}]
{
if
!
apiGroupVersionSet
[
schema
.
GroupVersion
{
Group
:
gvk
.
Group
,
Version
:
gvk
.
Version
}]
{
return
nil
,
fmt
.
Errorf
(
"unknown group version field %v in policy
file %s"
,
gvk
,
filePath
)
return
nil
,
fmt
.
Errorf
(
"unknown group version field %v in policy
"
,
gvk
)
}
}
if
err
:=
validation
.
ValidatePolicy
(
policy
);
err
!=
nil
{
if
err
:=
validation
.
ValidatePolicy
(
policy
);
err
!=
nil
{
...
@@ -74,8 +83,8 @@ func LoadPolicyFromFile(filePath string) (*auditinternal.Policy, error) {
...
@@ -74,8 +83,8 @@ func LoadPolicyFromFile(filePath string) (*auditinternal.Policy, error) {
policyCnt
:=
len
(
policy
.
Rules
)
policyCnt
:=
len
(
policy
.
Rules
)
if
policyCnt
==
0
{
if
policyCnt
==
0
{
return
nil
,
fmt
.
Errorf
(
"loaded illegal policy with 0 rules
from file %s"
,
filePath
)
return
nil
,
fmt
.
Errorf
(
"loaded illegal policy with 0 rules
"
)
}
}
glog
.
V
(
4
)
.
Infof
(
"Loaded %d audit policy rules
from file %s"
,
policyCnt
,
filePath
)
glog
.
V
(
4
)
.
Infof
(
"Loaded %d audit policy rules
"
,
policyCnt
)
return
policy
,
nil
return
policy
,
nil
}
}
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