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
4784a05d
Unverified
Commit
4784a05d
authored
Apr 16, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
Apr 16, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #76519 from haiyanmeng/readlimit-credentialprovider
Limit the read length of ioutil.ReadAll in `pkg/credentialprovider`
parents
a404238d
529ac8a2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
4 deletions
+30
-4
azure_acr_helper.go
pkg/credentialprovider/azure/azure_acr_helper.go
+8
-1
azure_credentials.go
pkg/credentialprovider/azure/azure_credentials.go
+10
-2
config.go
pkg/credentialprovider/config.go
+12
-1
No files found.
pkg/credentialprovider/azure/azure_acr_helper.go
View file @
4784a05d
...
@@ -47,7 +47,9 @@ package azure
...
@@ -47,7 +47,9 @@ package azure
import
(
import
(
"bytes"
"bytes"
"encoding/json"
"encoding/json"
"errors"
"fmt"
"fmt"
"io"
"io/ioutil"
"io/ioutil"
"net/http"
"net/http"
"net/url"
"net/url"
...
@@ -178,10 +180,15 @@ func performTokenExchange(
...
@@ -178,10 +180,15 @@ func performTokenExchange(
}
}
var
content
[]
byte
var
content
[]
byte
if
content
,
err
=
ioutil
.
ReadAll
(
exchange
.
Body
);
err
!=
nil
{
limitedReader
:=
&
io
.
LimitedReader
{
R
:
exchange
.
Body
,
N
:
maxReadLength
}
if
content
,
err
=
ioutil
.
ReadAll
(
limitedReader
);
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"Www-Authenticate: error reading response from %s"
,
authEndpoint
)
return
""
,
fmt
.
Errorf
(
"Www-Authenticate: error reading response from %s"
,
authEndpoint
)
}
}
if
limitedReader
.
N
<=
0
{
return
""
,
errors
.
New
(
"the read limit is reached"
)
}
var
authResp
acrAuthResponse
var
authResp
acrAuthResponse
if
err
=
json
.
Unmarshal
(
content
,
&
authResp
);
err
!=
nil
{
if
err
=
json
.
Unmarshal
(
content
,
&
authResp
);
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"Www-Authenticate: unable to read response %s"
,
content
)
return
""
,
fmt
.
Errorf
(
"Www-Authenticate: unable to read response %s"
,
content
)
...
...
pkg/credentialprovider/azure/azure_credentials.go
View file @
4784a05d
...
@@ -18,6 +18,7 @@ package azure
...
@@ -18,6 +18,7 @@ package azure
import
(
import
(
"context"
"context"
"errors"
"io"
"io"
"io/ioutil"
"io/ioutil"
"os"
"os"
...
@@ -38,7 +39,10 @@ import (
...
@@ -38,7 +39,10 @@ import (
var
flagConfigFile
=
pflag
.
String
(
"azure-container-registry-config"
,
""
,
var
flagConfigFile
=
pflag
.
String
(
"azure-container-registry-config"
,
""
,
"Path to the file containing Azure container registry configuration information."
)
"Path to the file containing Azure container registry configuration information."
)
const
dummyRegistryEmail
=
"name@contoso.com"
const
(
dummyRegistryEmail
=
"name@contoso.com"
maxReadLength
=
10
*
1
<<
20
// 10MB
)
var
containerRegistryUrls
=
[]
string
{
"*.azurecr.io"
,
"*.azurecr.cn"
,
"*.azurecr.de"
,
"*.azurecr.us"
}
var
containerRegistryUrls
=
[]
string
{
"*.azurecr.io"
,
"*.azurecr.cn"
,
"*.azurecr.de"
,
"*.azurecr.us"
}
...
@@ -117,10 +121,14 @@ func parseConfig(configReader io.Reader) (*auth.AzureAuthConfig, error) {
...
@@ -117,10 +121,14 @@ func parseConfig(configReader io.Reader) (*auth.AzureAuthConfig, error) {
return
&
config
,
nil
return
&
config
,
nil
}
}
configContents
,
err
:=
ioutil
.
ReadAll
(
configReader
)
limitedReader
:=
&
io
.
LimitedReader
{
R
:
configReader
,
N
:
maxReadLength
}
configContents
,
err
:=
ioutil
.
ReadAll
(
limitedReader
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
if
limitedReader
.
N
<=
0
{
return
nil
,
errors
.
New
(
"the read limit is reached"
)
}
err
=
yaml
.
Unmarshal
(
configContents
,
&
config
)
err
=
yaml
.
Unmarshal
(
configContents
,
&
config
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
...
pkg/credentialprovider/config.go
View file @
4784a05d
...
@@ -19,7 +19,9 @@ package credentialprovider
...
@@ -19,7 +19,9 @@ package credentialprovider
import
(
import
(
"encoding/base64"
"encoding/base64"
"encoding/json"
"encoding/json"
"errors"
"fmt"
"fmt"
"io"
"io/ioutil"
"io/ioutil"
"net/http"
"net/http"
"os"
"os"
...
@@ -30,6 +32,10 @@ import (
...
@@ -30,6 +32,10 @@ import (
"k8s.io/klog"
"k8s.io/klog"
)
)
const
(
maxReadLength
=
10
*
1
<<
20
// 10MB
)
// DockerConfigJson represents ~/.docker/config.json file info
// DockerConfigJson represents ~/.docker/config.json file info
// see https://github.com/docker/docker/pull/12009
// see https://github.com/docker/docker/pull/12009
type
DockerConfigJson
struct
{
type
DockerConfigJson
struct
{
...
@@ -195,11 +201,16 @@ func ReadUrl(url string, client *http.Client, header *http.Header) (body []byte,
...
@@ -195,11 +201,16 @@ func ReadUrl(url string, client *http.Client, header *http.Header) (body []byte,
}
}
}
}
contents
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
limitedReader
:=
&
io
.
LimitedReader
{
R
:
resp
.
Body
,
N
:
maxReadLength
}
contents
,
err
:=
ioutil
.
ReadAll
(
limitedReader
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
if
limitedReader
.
N
<=
0
{
return
nil
,
errors
.
New
(
"the read limit is reached"
)
}
return
contents
,
nil
return
contents
,
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