Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated cherry pick of #13594 #13832

Merged
merged 1 commit into from
Sep 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion cluster/gce/configure-vm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,11 @@ grains:
- kubernetes-master
cloud: gce
EOF
if ! [[ -z "${PROJECT_ID:-}" ]] && ! [[ -z "${TOKEN_URL:-}" ]] && ! [[ -z "${NODE_NETWORK:-}" ]] ; then
if ! [[ -z "${PROJECT_ID:-}" ]] && ! [[ -z "${TOKEN_URL:-}" ]] && ! [[ -z "${TOKEN_BODY:-}" ]] && ! [[ -z "${NODE_NETWORK:-}" ]] ; then
cat <<EOF >/etc/gce.conf
[global]
token-url = ${TOKEN_URL}
token-body = ${TOKEN_BODY}
project-id = ${PROJECT_ID}
network-name = ${NODE_NETWORK}
EOF
Expand Down
3 changes: 2 additions & 1 deletion pkg/cloudprovider/gce/gce.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type GCECloud struct {
type Config struct {
Global struct {
TokenURL string `gcfg:"token-url"`
TokenBody string `gcfg:"token-body"`
ProjectID string `gcfg:"project-id"`
NetworkName string `gcfg:"network-name"`
}
Expand Down Expand Up @@ -180,7 +181,7 @@ func newGCECloud(config io.Reader) (*GCECloud, error) {
networkName = cfg.Global.NetworkName
}
if cfg.Global.TokenURL != "" {
tokenSource = newAltTokenSource(cfg.Global.TokenURL)
tokenSource = newAltTokenSource(cfg.Global.TokenURL, cfg.Global.TokenBody)
}
}
client := oauth2.NewClient(oauth2.NoContext, tokenSource)
Expand Down
13 changes: 8 additions & 5 deletions pkg/cloudprovider/gce/token_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package gce_cloud
import (
"encoding/json"
"net/http"
"strings"
"time"

"k8s.io/kubernetes/pkg/util"
Expand Down Expand Up @@ -59,6 +60,7 @@ func init() {
type altTokenSource struct {
oauthClient *http.Client
tokenURL string
tokenBody string
throttle util.RateLimiter
}

Expand All @@ -73,7 +75,7 @@ func (a *altTokenSource) Token() (*oauth2.Token, error) {
}

func (a *altTokenSource) token() (*oauth2.Token, error) {
req, err := http.NewRequest("GET", a.tokenURL, nil)
req, err := http.NewRequest("POST", a.tokenURL, strings.NewReader(a.tokenBody))
if err != nil {
return nil, err
}
Expand All @@ -86,23 +88,24 @@ func (a *altTokenSource) token() (*oauth2.Token, error) {
return nil, err
}
var tok struct {
AccessToken string `json:"accessToken"`
ExpiryTimeSeconds int64 `json:"expiryTimeSeconds,string"`
AccessToken string `json:"accessToken"`
ExpireTime time.Time `json:"expireTime"`
}
if err := json.NewDecoder(res.Body).Decode(&tok); err != nil {
return nil, err
}
return &oauth2.Token{
AccessToken: tok.AccessToken,
Expiry: time.Unix(tok.ExpiryTimeSeconds, 0),
Expiry: tok.ExpireTime,
}, nil
}

func newAltTokenSource(tokenURL string) oauth2.TokenSource {
func newAltTokenSource(tokenURL, tokenBody string) oauth2.TokenSource {
client := oauth2.NewClient(oauth2.NoContext, google.ComputeTokenSource(""))
a := &altTokenSource{
oauthClient: client,
tokenURL: tokenURL,
tokenBody: tokenBody,
throttle: util.NewTokenBucketRateLimiter(tokenURLQPS, tokenURLBurst),
}
return oauth2.ReuseTokenSource(nil, a)
Expand Down