Skip to content

Commit 4fe8df3

Browse files
authored
(ESPSTUDIO-8275) (#6)
Plugin deployment option for different namespaces on Viya Update readme to reflect that the scripts are now run separate configure-grafana.sh and then the appropriate register-oauth-client-*.sh no longer need to provide the whole plugin url, just the version
1 parent 4d95ab5 commit 4fe8df3

File tree

5 files changed

+136
-37
lines changed

5 files changed

+136
-37
lines changed

README.md

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,11 @@ This section is relevant only to internal users at SAS.
8181

8282
### Install a Released Version of the Plug-in
8383

84-
An installation script is provided to install the plug-in and configure Grafana. The installation script performs the following tasks:
85-
* Modifies the Grafana deployment by adding the GF_INSTALL_PLUGINS environment variable to enable Grafana to install the plug-in.
86-
* Configures a new `grafana.ini` file to enable OAuth authentication.
87-
* Configures Grafana as an OAuth client with the chosen OAuth provider. Users of Grafana are directed to use the OAuth login page.
88-
* Optionally installs Grafana for you.
89-
90-
Use the installation script to install the plug-in:
84+
Installation scripts are provided to install the plug-in and configure Grafana. These scripts perform the following tasks:
85+
* Modify the Grafana deployment by adding the GF_INSTALL_PLUGINS environment variable to enable Grafana to install the plug-in.
86+
* Configure a new `grafana.ini` file to enable OAuth authentication.
87+
* Configure Grafana as an OAuth client with the chosen OAuth provider. Users of Grafana are directed to use the OAuth login page.
88+
* Optionally install Grafana for you.
9189

9290
1. Set the correct Kubernetes configuration file for your environment.
9391
```
@@ -105,16 +103,39 @@ Use the installation script to install the plug-in:
105103
```
106104
export GRAFANA_NAMESPACE=grafana
107105
```
108-
5. Run the installation script, adjusting the command to specify the following variables:
106+
5. Run `configure-grafana.sh`, adjusting the command to specify the following variables:
109107
- The Kubernetes _namespace_ in which SAS Event Stream Processing is installed.
110108
- The _version_ of the plug-in that you want to install. Ensure that you specify a version of the plug-in that is compatible with your version of Grafana.
111-
- The _oauth-provider_ of the environment. Select one of the following options: **uaa**, **keycloak** or **viya**.
109+
- The _oauth-provider_ of the environment. Select one of the following options: `uaa`, `keycloak` or `viya`.
112110
> **Caution**: Running the installation script might overwrite any existing Grafana configuration.
113111
114112
```
115113
cd ./install
116-
bash configure-grafana.sh <namespace> https://github.com/sassoftware/grafana-esp-plugin/download/<version>/sasesp-plugin-<version>.zip <oauth-provider>
114+
bash configure-grafana.sh <namespace> <version> <oauth-provider>
115+
```
116+
6. Run one of the following three scripts, depending on your chosen OAuth provider. Adjust the command to specify the following variables.
117+
- The Kubernetes namespace in which SAS Event Stream Processing is installed, _esp-namespace_.
118+
- (Optional) The Kubernetes namespace in which Grafana is installed, _grafana-namespace_ if this differs from the namespace in which SAS Event Stream Processing is installed.
119+
```
120+
bash register-oauth-client-keycloak.sh <esp-namespace> <grafana-namespace>
121+
```
122+
```
123+
bash register-oauth-client-uaa.sh <esp-namespace> <grafana-namespace>
124+
```
117125
```
126+
bash register-oauth-client-viya.sh <esp-namespace> <grafana-namespace>
127+
```
128+
7. If your OAuth provider is the SAS Viya platform and Grafana is not running in the same namespace as the SAS Viya platform, you must update the Content Security Policy (CSP) for SAS Logon to allow the Grafana host name to be used as a target of form submission.
129+
If you do not update the CSP, the browser blocks the redirect. You can update the CSP in one of the following two ways:
130+
- Use SAS Environment Manager to update the _content-security-policy_ value under the _sas.commons.web.security_ section.
131+
- Update the _sas-logon-app_ deployment to add the _SAS_COMMONS_WEB_SECURITY_CONTENTSECURITYPOLICY_ environment variable.
132+
133+
Update either SAS Environment Manager or the _sas-logon-app_ deployment with the following value, substituting the Grafana host name:
134+
```
135+
default-src 'self'; style-src 'self'; font-src 'self' data:;
136+
frame-ancestors 'self'; form-action 'self' <grafana-host>;
137+
```
138+
118139
119140
### (Optional) Build and Install a Privately Signed Version of the Plug-in
120141

install/configure-grafana.sh

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -e -o pipefail -o nounset
44

55
#input variables
66
ESP_NAMESPACE="${1}"; export ESP_NAMESPACE
7-
ESP_PLUGIN_SOURCE="${2}"
7+
ESP_PLUGIN_VERSION="${2}"
88
OAUTH_TYPE="${3:-uaa}"
99

1010
#optional environment variables - exported for use in other scripts
@@ -25,12 +25,12 @@ function check_requirements() {
2525
}
2626

2727
[ -z "${ESP_NAMESPACE}" ] && {
28-
echo "Usage: ${0} <namespace> <plugin-zip-url> <oauth-type>" >&2
28+
echo "Usage: ${0} <namespace> <version> <oauth-type>" >&2
2929
exit 1
3030
}
3131

32-
[ -z "${ESP_PLUGIN_SOURCE}" ] && {
33-
echo "Usage: ${0} <namespace> <plugin-zip-url> <oauth-type>" >&2
32+
[ -z "${ESP_PLUGIN_VERSION}" ] && {
33+
echo "Usage: ${0} <namespace> <version> <oauth-type>" >&2
3434
exit 1
3535
}
3636

@@ -75,40 +75,29 @@ function generate_manifests() {
7575
check_requirements
7676

7777
echo "Fetching required deployment information..."
78-
ESP_DOMAIN=$(kubectl -n "${ESP_NAMESPACE}" get ingress --output json | jq -r '.items[0].spec.rules[0].host')
79-
export ESP_DOMAIN
8078

79+
#duplicate domain code
80+
ESP_DOMAIN=$(kubectl -n "${ESP_NAMESPACE}" get ingress --output json | jq -r '.items[0].spec.rules[0].host')
8181
GRAFANA_DOMAIN=$(kubectl -n "${GRAFANA_NAMESPACE}" get ingress --output json | jq -r '.items[0].spec.rules[0].host')
82+
ESP_PLUGIN_SOURCE="https://github.com/sassoftware/grafana-esp-plugin/download/$ESP_PLUGIN_VERSION/sasesp-plugin-$ESP_PLUGIN_VERSION.zip"
8283

8384
echo "Adding Grafana to allowed OAuth client redirects..."
8485
if [ "${OAUTH_TYPE}" == "viya" ]; then
8586

86-
if [[ "${DRY_RUN}" == false ]]; then
87-
bash register-oauth-client-viya.sh
88-
fi
89-
9087
TEMPLATE_AUTH_URL="https://${ESP_DOMAIN}/SASLogon/oauth/authorize"
9188
TEMPLATE_TOKEN_URL="https://${ESP_DOMAIN}/SASLogon/oauth/token"
9289
TEMPLATE_API_URL="https://${ESP_DOMAIN}/SASLogon/userinfo"
9390
TEMPLATE_SIGNOUT_REDIRECT_URL="https://${ESP_DOMAIN}/SASLogon/logout.do"
9491

9592
elif [ "${OAUTH_TYPE}" == "keycloak" ]; then
9693

97-
if [[ "${DRY_RUN}" == false ]]; then
98-
bash register-oauth-client-keycloak.sh
99-
fi
100-
10194
TEMPLATE_AUTH_URL="https://${ESP_DOMAIN}/${KEYCLOAK_SUBPATH}/realms/sas-esp/protocol/openid-connect/auth"
10295
TEMPLATE_TOKEN_URL="https://${ESP_DOMAIN}/${KEYCLOAK_SUBPATH}/realms/sas-esp/protocol/openid-connect/token"
10396
TEMPLATE_API_URL="https://${ESP_DOMAIN}/${KEYCLOAK_SUBPATH}/realms/sas-esp/protocol/openid-connect/userinfo"
10497
TEMPLATE_SIGNOUT_REDIRECT_URL="https://${ESP_DOMAIN}/${KEYCLOAK_SUBPATH}/realms/sas-esp/protocol/openid-connect/logout?client_id=${OAUTH_CLIENT_ID}\&post_logout_redirect_uri=https://${ESP_DOMAIN}/grafana/login"
10598

10699
else
107100

108-
if [[ "${DRY_RUN}" == false ]]; then
109-
bash register-oauth-client-uaa.sh
110-
fi
111-
112101
TEMPLATE_AUTH_URL="https://${ESP_DOMAIN}/uaa/oauth/authorize"
113102
TEMPLATE_TOKEN_URL="https://${ESP_DOMAIN}/uaa/oauth/token?token_format=jwt"
114103
TEMPLATE_API_URL="https://${ESP_DOMAIN}/uaa/userinfo"
@@ -129,12 +118,13 @@ echo "Generating manifests..."
129118
generate_manifests
130119

131120
if [[ "${DRY_RUN}" == true ]]; then
121+
#GF_INSTALL_PLUGINS_VALUE=$(kubectl -n "${ESP_NAMESPACE}" get deployment/grafana --output json | jq -c '.spec.template.spec.containers[0].env[] | select(.name | contains("GF_INSTALL_PLUGINS")) | .value')
132122
exit 0
133123
fi
134124

135125
if [[ "${INSTALL_GRAFANA}" == true ]]; then
136126
echo "Installing grafana"
137-
kubectl -n "${ESP_NAMESPACE}" apply -f ./manifests/grafana.yaml
127+
kubectl -n "${GRAFANA_NAMESPACE}" apply -f ./manifests/grafana.yaml
138128
fi
139129

140130
echo "Applying config-map.yaml"

install/register-oauth-client-keycloak.sh

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22

33
set -e -o pipefail -o nounset
44

5+
ESP_NAMESPACE="${1}"
6+
KEYCLOAK_SUBPATH="${KEYCLOAK_SUBPATH:-auth}"
7+
8+
function usage () {
9+
echo "Usage: ${0} <esp-namespace> " >&2
10+
exit 1
11+
}
12+
13+
[ -z "$KUBECONFIG" ] && {
14+
echo "KUBECONFIG environment variable unset." >&2
15+
exit 1
16+
}
17+
18+
[ -z "${ESP_NAMESPACE}" ] && {
19+
usage
20+
}
21+
22+
ESP_DOMAIN=$(kubectl -n "${ESP_NAMESPACE}" get ingress --output json | jq -r '.items[0].spec.rules[0].host')
23+
524
function check_keycloak_deployment() {
625
if ! kubectl -n "${ESP_NAMESPACE}" get deployment keycloak-deployment 2>/dev/null 1>&2; then
726
echo >&2 "ERROR: No Keycloak deployment found under namespace ${ESP_NAMESPACE}."
@@ -40,7 +59,7 @@ function check_requirements() {
4059

4160
# Fetch access token to perform admin tasks:
4261
function fetch_keycloak_admin_token() {
43-
_resp=$(curl "https://${ESP_DOMAIN}/${KEYCLOAK_SUBPATH}/realms/master/protocol/openid-connect/token" -s -k -X POST \
62+
_resp=$(curl "https://${ESP_DOMAIN}/${KEYCLOAK_SUBPATH}/realms/master/protocol/openid-connect/token" -k -X POST \
4463
-H 'Content-Type: application/x-www-form-urlencoded' \
4564
-H 'Accept: application/json' \
4665
-d "client_id=admin-cli&grant_type=password&username=${KEYCLOAK_ADMIN}&password=${KEYCLOAK_SECRET}")
@@ -51,7 +70,7 @@ function fetch_keycloak_admin_token() {
5170
function create_role() {
5271
_role_name="${1}"
5372
_role_repr="{\"name\": \"${_role_name}\", \"clientRole\": true}"
54-
curl "https://${ESP_DOMAIN}/${KEYCLOAK_SUBPATH}/admin/realms/sas-esp/clients/${_client_id}/roles" -s -k -X POST \
73+
curl "https://${ESP_DOMAIN}/${KEYCLOAK_SUBPATH}/admin/realms/sas-esp/clients/${_client_id}/roles" -k -X POST \
5574
-H "Content-Type: application/json" \
5675
-H "Authorization: Bearer ${_token}" \
5776
-d "${_role_repr}"
@@ -75,7 +94,7 @@ function add_protocol_mapper() {
7594
}
7695
}")
7796
_mapper_body=$(echo "${_mapper_repr}" | jq -r -c)
78-
curl -s -k -X POST \
97+
curl -k -X POST \
7998
"https://${ESP_DOMAIN}/${KEYCLOAK_SUBPATH}/admin/realms/sas-esp/clients/${_client_id}/protocol-mappers/models" \
8099
-H "Content-Type: application/json" \
81100
-H "Authorization: Bearer ${_token}" \
@@ -85,7 +104,7 @@ function add_protocol_mapper() {
85104
function prepare_keycloak_roles() {
86105
_token="$(fetch_keycloak_admin_token)"
87106
# Get sas-esp realm clients:
88-
_kc_clients=$(curl -s -k -X GET "https://${ESP_DOMAIN}/${KEYCLOAK_SUBPATH}/admin/realms/sas-esp/clients" -H "Authorization: Bearer ${_token}")
107+
_kc_clients=$(curl -k -X GET "https://${ESP_DOMAIN}/${KEYCLOAK_SUBPATH}/admin/realms/sas-esp/clients" -H "Authorization: Bearer ${_token}")
89108
# Get OAuth2 Proxy client ID:
90109
_client_id=$(echo "${_kc_clients}" | jq -r --arg opid "${OAUTH_CLIENT_ID}" '.[] | select(.clientId == $opid) | .id')
91110
# Create Grafana roles:
@@ -106,4 +125,11 @@ export OAUTH_CLIENT_ID
106125
OAUTH_CLIENT_SECRET=$(echo "${_oauth2_proxy_secret}" | jq -r '.data.OAUTH2_PROXY_CLIENT_SECRET | @base64d')
107126
export OAUTH_CLIENT_SECRET
108127

128+
cat <<EOF
129+
OAuth details:
130+
ESP Domain: ${ESP_DOMAIN}
131+
OAuth client ID: ${OAUTH_CLIENT_ID}
132+
OAuth client secret: ${OAUTH_CLIENT_SECRET}
133+
EOF
134+
109135
prepare_keycloak_roles

install/register-oauth-client-uaa.sh

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,31 @@
22

33
set -e -o pipefail -o nounset
44

5+
ESP_NAMESPACE="${1}"
6+
GRAFANA_NAMESPACE="${2:-${ESP_NAMESPACE}}"
7+
OAUTH_CLIENT_ID="${OAUTH_CLIENT_ID:-sv_client}"; export OAUTH_CLIENT_ID
8+
OAUTH_CLIENT_SECRET="${OAUTH_CLIENT_SECRET:-secret}"; export OAUTH_CLIENT_SECRET
9+
10+
function usage () {
11+
echo "Usage: ${0} <esp-namespace> " >&2
12+
exit 1
13+
}
14+
15+
[ -z "$KUBECONFIG" ] && {
16+
echo "KUBECONFIG environment variable unset." >&2
17+
exit 1
18+
}
19+
20+
[ -z "${ESP_NAMESPACE}" ] && {
21+
usage
22+
}
23+
24+
ESP_DOMAIN=$(kubectl -n "${ESP_NAMESPACE}" get ingress --output json | jq -r '.items[0].spec.rules[0].host')
25+
GRAFANA_DOMAIN=$(kubectl -n "${GRAFANA_NAMESPACE}" get ingress --output json | jq -r '.items[0].spec.rules[0].host')
26+
527
# Fetch access token to perform admin tasks:
628
function fetch_uaa_admin_token() {
7-
_resp=$(curl "https://${ESP_DOMAIN}/uaa/oauth/token" -s -k -X POST \
29+
_resp=$(curl "https://${ESP_DOMAIN}/uaa/oauth/token" -k -X POST \
830
-H 'Content-Type: application/x-www-form-urlencoded' \
931
-H 'Accept: application/json' \
1032
-d "client_id=${UAA_ADMIN}&client_secret=${UAA_SECRET}&grant_type=client_credentials&response_type=token")
@@ -15,14 +37,14 @@ function fetch_uaa_admin_token() {
1537
# Add Grafana generic OAuth to allowed auth redirects:
1638
function add_grafana_auth_redirect_uaa() {
1739
_token="$(fetch_uaa_admin_token)"
18-
_redirect="https://${ESP_DOMAIN}/grafana/login/generic_oauth"
40+
_redirect="https://${GRAFANA_DOMAIN}/grafana/login/generic_oauth"
1941

20-
_config=$(curl -s -k -X GET "https://${ESP_DOMAIN}/uaa/oauth/clients/${OAUTH_CLIENT_ID}" -H "Authorization: Bearer ${_token}")
42+
_config=$(curl -k -X GET "https://${ESP_DOMAIN}/uaa/oauth/clients/${OAUTH_CLIENT_ID}" -H "Authorization: Bearer ${_token}")
2143

2244
_update_body=$(echo "${_config}" | jq -c -r --arg redirect "${_redirect}" \
2345
'.redirect_uri += [$redirect] | {client_id: .client_id, redirect_uri: .redirect_uri}')
2446

25-
_resp=$(curl "https://${ESP_DOMAIN}/uaa/oauth/clients/${OAUTH_CLIENT_ID}" -s -k -X PUT \
47+
_resp=$(curl "https://${ESP_DOMAIN}/uaa/oauth/clients/${OAUTH_CLIENT_ID}" -k -X PUT \
2648
-o /dev/null -w "%{http_code}" \
2749
-H 'Content-Type: application/json' \
2850
-H "Authorization: Bearer ${_token}" \
@@ -43,4 +65,14 @@ export UAA_ADMIN
4365
UAA_SECRET=$(echo "${_uaa_secret_data}" | jq -r '.data.password | @base64d')
4466
export UAA_SECRET
4567

68+
cat <<EOF
69+
OAuth details:
70+
ESP Domain: ${ESP_DOMAIN}
71+
Grafana Domain: ${GRAFANA_DOMAIN}
72+
OAuth client ID: ${OAUTH_CLIENT_ID}
73+
OAuth client secret: ${OAUTH_CLIENT_SECRET}
74+
UAA Admin: ${UAA_ADMIN}
75+
UAA secret: ${UAA_SECRET}
76+
EOF
77+
4678
add_grafana_auth_redirect_uaa

install/register-oauth-client-viya.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,28 @@
22

33
set -e -o pipefail -o nounset
44

5+
ESP_NAMESPACE="${1}"
6+
GRAFANA_NAMESPACE="${2:-${ESP_NAMESPACE}}"
7+
OAUTH_CLIENT_ID="${OAUTH_CLIENT_ID:-sv_client}"; export OAUTH_CLIENT_ID
8+
OAUTH_CLIENT_SECRET="${OAUTH_CLIENT_SECRET:-secret}"; export OAUTH_CLIENT_SECRET
9+
10+
function usage () {
11+
echo "Usage: ${0} <viya-namespace> <grafana-namespace>" >&2
12+
exit 1
13+
}
14+
15+
[ -z "$KUBECONFIG" ] && {
16+
echo "KUBECONFIG environment variable unset." >&2
17+
exit 1
18+
}
19+
20+
[ -z "${ESP_NAMESPACE}" ] && {
21+
usage
22+
}
23+
24+
ESP_DOMAIN=$(kubectl -n "${ESP_NAMESPACE}" get ingress --output json | jq -r '.items[0].spec.rules[0].host')
25+
GRAFANA_DOMAIN=$(kubectl -n "${GRAFANA_NAMESPACE}" get ingress --output json | jq -r '.items[0].spec.rules[0].host')
26+
527
function fetch_consul_token () {
628
_token=$(kubectl -n "${ESP_NAMESPACE}" get secret sas-consul-client -o go-template='{{ .data.CONSUL_TOKEN | base64decode}}')
729

@@ -48,4 +70,12 @@ function register_oauth_client () {
4870

4971
}
5072

73+
cat <<EOF
74+
OAuth details:
75+
ESP Domain: ${ESP_DOMAIN}
76+
Grafana Domain: ${GRAFANA_DOMAIN}
77+
OAuth client ID: ${OAUTH_CLIENT_ID}
78+
OAuth client secret: ${OAUTH_CLIENT_SECRET}
79+
EOF
80+
5181
register_oauth_client

0 commit comments

Comments
 (0)