Skip to content

Commit

Permalink
Update nozzle with client-id and client-secret for authentication (#205)
Browse files Browse the repository at this point in the history
* Update nozzle with client-id and client-secret for token refresh mechanism.
* CI update
* Readme update
  • Loading branch information
luckyj5 authored Aug 5, 2019
1 parent c8493db commit 531fc26
Show file tree
Hide file tree
Showing 456 changed files with 343 additions and 92,624 deletions.
2 changes: 2 additions & 0 deletions .circleci/ci_nozzle_manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ applications:
API_ENDPOINT:
API_USER:
API_PASSWORD:
CLIENT_ID:
CLIENT_SECRET:
SPLUNK_HOST:
SPLUNK_TOKEN:
SPLUNK_INDEX:
Expand Down
2 changes: 2 additions & 0 deletions .circleci/update_manifest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ set -e
sed -i 's@API_ENDPOINT:.*@'"API_ENDPOINT: $API_ENDPOINT"'@' .circleci/ci_nozzle_manifest.yml
sed -i 's@API_USER:.*@'"API_USER: $API_USER"'@' .circleci/ci_nozzle_manifest.yml
sed -i 's@API_PASSWORD:.*@'"API_PASSWORD: $API_PASSWORD"'@' .circleci/ci_nozzle_manifest.yml
sed -i 's@CLIENT_ID:.*@'"CLIENT_ID: $CLIENT_ID"'@' .circleci/ci_nozzle_manifest.yml
sed -i 's@CLIENT_SECRET:.*@'"CLIENT_SECRET: $CLIENT_SECRET"'@' .circleci/ci_nozzle_manifest.yml
sed -i 's@SPLUNK_HOST:.*@'"SPLUNK_HOST: $SPLUNK_HOST"'@' .circleci/ci_nozzle_manifest.yml
sed -i 's@SPLUNK_TOKEN:.*@'"SPLUNK_TOKEN: $SPLUNK_TOKEN"'@' .circleci/ci_nozzle_manifest.yml
sed -i 's@SPLUNK_INDEX:.*@'"SPLUNK_INDEX: $SPLUNK_INDEX"'@' .circleci/ci_nozzle_manifest.yml
Expand Down
32 changes: 19 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,36 @@ In addition, logs from the nozzle itself are of sourcetype `cf:splunknozzle`.

### Setup

The Nozzle requires a user with the scope `doppler.firehose` and
`cloud_controller.admin_read_only` (the latter is only required if `ADD_APP_INFO` is true). If `cloud_controller.admin_read_only` is not
The Nozzle requires a client with the authorities `doppler.firehose` and `cloud_controller.admin_read_only` (the latter is only required if `ADD_APP_INFO` is true) and grant-types `client_credentials` and `refresh_token`. If `cloud_controller.admin_read_only` is not
available in the system, switch to use `cloud_controller.admin`.

You can either
* Add the user manually using [uaac](https://github.com/cloudfoundry/cf-uaac)
* Add a new user to the deployment manifest; see [uaa.scim.users](https://github.com/cloudfoundry/uaa-release/blob/master/jobs/uaa/spec)
* Add the client manually using [uaac](https://github.com/cloudfoundry/cf-uaac)
* Add the client to the deployment manifest; see [uaa.scim.users](https://github.com/cloudfoundry/uaa-release/blob/master/jobs/uaa/spec)

Manifest example:

```yaml
uaa:
scim:
users:
- splunk-firehose|password123|cloud_controller.admin_read_only,doppler.firehose

# Clients
uaa.clients:
splunk-firehose:
id: splunk-firehose
override: true
secret: splunk-firehose-secret
authorized-grant-types: client_credentials,refresh_token
authorities: doppler.firehose,cloud_controller.admin_read_only
```
`uaac` example:
```shell
uaac target https://uaa.[system domain url]
uaac token client get admin -s [admin client credentials secret]
uaac -t user add splunk-nozzle --password password123 --emails na
uaac -t member add cloud_controller.admin_read_only splunk-nozzle
uaac -t member add doppler.firehose splunk-nozzle
uaac client add splunk-firehose --name splunk-firehose
uaac client add splunk-firehose --secret [your_client_secret]
uaac client add splunk-firehose --authorized_grant_types client_credentials,refresh_token
uaac client add splunk-firehose --authorities doppler.firehose,cloud_controller.admin_read_only
```

`cloud_controller.admin_read_only` will work for cf v241
Expand All @@ -55,8 +61,8 @@ You can declare parameters by making a copy of the scripts/nozzle.sh.template.

__Cloud Foundry configuration parameters:__
* `API_ENDPOINT`: Cloud Foundry API endpoint address.
* `API_USER`: Cloud Foundry user name. (Must have scope described above)
* `API_PASSWORD`: Cloud Foundry user password.
* `CLIENT_ID`: UAA Client ID (Must have authorities and grant_types described above).
* `CLIENT_SECRET`: Secret for Client ID.

__Splunk configuration parameters:__
* `SPLUNK_TOKEN`: [Splunk HTTP event collector token](http://docs.splunk.com/Documentation/Splunk/latest/Data/UsetheHTTPEventCollector/).
Expand Down
1 change: 1 addition & 0 deletions cache/boltdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ func (c *Boltdb) fromPCFApp(app *cfclient.App) *App {
Guid: app.Guid,
SpaceGuid: app.SpaceGuid,
IgnoredApp: c.isOptOut(app.Environment),
CfAppEnv: app.Environment,
}

c.fillOrgAndSpace(cachedApp)
Expand Down
4 changes: 2 additions & 2 deletions ci/nozzle_manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ applications:
env:
GOPACKAGENAME: main
API_ENDPOINT:
API_USER:
API_PASSWORD:
CLIENT_ID:
CLIENT_SECRET:
SPLUNK_HOST:
SPLUNK_TOKEN:
SPLUNK_INDEX:
Expand Down
2 changes: 1 addition & 1 deletion glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 11 additions & 5 deletions splunknozzle/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import (
)

type Config struct {
ApiEndpoint string `json:"api-endpoint"`
User string `json:"-"`
Password string `json:"-"`
ApiEndpoint string `json:"api-endpoint"`
User string `json:"-"`
Password string `json:"-"`
ClientID string `json:"-"`
ClientSecret string `json:"-"`

SplunkToken string `json:"-"`
SplunkHost string `json:"splunk-host"`
Expand Down Expand Up @@ -67,9 +69,13 @@ func NewConfigFromCmdFlags(version, branch, commit, buildos string) *Config {
kingpin.Flag("api-endpoint", "API endpoint address").
OverrideDefaultFromEnvar("API_ENDPOINT").Required().StringVar(&c.ApiEndpoint)
kingpin.Flag("user", "Admin user.").
OverrideDefaultFromEnvar("API_USER").Required().StringVar(&c.User)
OverrideDefaultFromEnvar("API_USER").StringVar(&c.User)
kingpin.Flag("password", "Admin password.").
OverrideDefaultFromEnvar("API_PASSWORD").Required().StringVar(&c.Password)
OverrideDefaultFromEnvar("API_PASSWORD").StringVar(&c.Password)
kingpin.Flag("client-id", "Client ID.").
OverrideDefaultFromEnvar("CLIENT_ID").Required().StringVar(&c.ClientID)
kingpin.Flag("client-secret", "Client secret.").
OverrideDefaultFromEnvar("CLIENT_SECRET").Required().StringVar(&c.ClientSecret)

kingpin.Flag("splunk-host", "Splunk HTTP event collector host").
OverrideDefaultFromEnvar("SPLUNK_HOST").Required().StringVar(&c.SplunkHost)
Expand Down
8 changes: 8 additions & 0 deletions splunknozzle/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ var _ = Describe("Config", func() {
os.Setenv("API_ENDPOINT", "api.bosh-lite.com")
os.Setenv("API_USER", "admin")
os.Setenv("API_PASSWORD", "abc123")
os.Setenv("CLIENT_ID", "client123")
os.Setenv("CLIENT_SECRET", "secret123")

os.Setenv("SPLUNK_TOKEN", "sometoken")
os.Setenv("SPLUNK_HOST", "splunk.example.com")
Expand Down Expand Up @@ -69,6 +71,8 @@ var _ = Describe("Config", func() {
Expect(c.ApiEndpoint).To(Equal("api.bosh-lite.com"))
Expect(c.User).To(Equal("admin"))
Expect(c.Password).To(Equal("abc123"))
Expect(c.ClientID).To(Equal("client123"))
Expect(c.ClientSecret).To(Equal("secret123"))

Expect(c.SplunkHost).To(Equal("splunk.example.com"))
Expect(c.SplunkToken).To(Equal("sometoken"))
Expand Down Expand Up @@ -160,6 +164,8 @@ var _ = Describe("Config", func() {
"--api-endpoint=api.bosh-lite.comc",
"--user=adminc",
"--password=abc123c",
"--client-id=client123",
"--client-secret=secret123",
"--splunk-host=splunk.example.comc",
"--splunk-token=sometokenc",
"--splunk-index=splunk_indexc",
Expand Down Expand Up @@ -196,6 +202,8 @@ var _ = Describe("Config", func() {
Expect(c.ApiEndpoint).To(Equal("api.bosh-lite.comc"))
Expect(c.User).To(Equal("adminc"))
Expect(c.Password).To(Equal("abc123c"))
Expect(c.ClientID).To(Equal("client123"))
Expect(c.ClientSecret).To(Equal("secret123"))

Expect(c.SplunkHost).To(Equal("splunk.example.comc"))
Expect(c.SplunkToken).To(Equal("sometokenc"))
Expand Down
3 changes: 2 additions & 1 deletion splunknozzle/nozzle.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func (s *SplunkFirehoseNozzle) PCFClient() (*cfclient.Client, error) {
Username: s.config.User,
Password: s.config.Password,
SkipSslValidation: s.config.SkipSSLCF,
ClientID: s.config.ClientID,
ClientSecret: s.config.ClientSecret,
}

return cfclient.NewClient(cfConfig)
Expand Down Expand Up @@ -80,7 +82,6 @@ func (s *SplunkFirehoseNozzle) EventSink(logger lager.Logger) (eventsink.Sink, e
Logger: logger,
}


var writers []eventwriter.Writer
for i := 0; i < s.config.HecWorkers+1; i++ {
splunkWriter := eventwriter.NewSplunk(writerConfig)
Expand Down
8 changes: 5 additions & 3 deletions splunknozzle/nozzle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ import (

func newConfig() *Config {
return &Config{
ApiEndpoint: "http://localhost:9911",
User: "admin",
Password: "admin",
ApiEndpoint: "http://localhost:9911",
User: "admin",
Password: "admin",
ClientID: "admin",
ClientSecret: "admin",

SplunkToken: "token",
SplunkHost: "localhost:8088",
Expand Down
3 changes: 2 additions & 1 deletion tile/tile-history.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ history:
- 1.0.1
- 1.0.2
- 1.1.0
version: 1.1.1
- 1.1.1
version: 1.1.2
12 changes: 6 additions & 6 deletions tile/tile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ forms:
type: string
label: API Endpoint
description: Cloud Foundry API endpoint.
- name: api_user
- name: client_id
type: string
label: API User
description: API username
- name: api_password
label: Client ID
description: CF UAA client ID
- name: client_secret
type: secret
label: API Password
description: Password for API user
label: Client Secret
description: CF UAA client secret
- name: skip_ssl_validation_cf
type: boolean
label: Skip SSL Validation
Expand Down
10 changes: 10 additions & 0 deletions vendor/github.com/cloudfoundry-incubator/uaago/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 531fc26

Please sign in to comment.