Skip to content

Commit 8feba81

Browse files
authored
Add docs and error message for allowing other IAM users to access cluster commands (#1392)
1 parent 22f0c33 commit 8feba81

File tree

5 files changed

+41
-0
lines changed

5 files changed

+41
-0
lines changed

docs/miscellaneous/security.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,33 @@ It is possible to further restrict access by limiting access to particular resou
7676
### CLI
7777

7878
In order to connect to the operator via the CLI, you must provide valid AWS credentials for any user with access to the account. No special permissions are required. The CLI can be configured using the `cortex env configure ENVIRONMENT_NAME` command (e.g. `cortex env configure aws`).
79+
80+
### Running `cortex cluster` commands from different IAM users
81+
82+
By default, the `cortex cluster *` commands can only be executed by the IAM user who created the Cortex cluster. To grant access to additional IAM users, follow these steps:
83+
84+
1. Install `eksctl` by following these [instructions](https://eksctl.io/introduction/#installation).
85+
86+
1. Determine the ARN of the IAM user that you would like to grant access to. You can get the ARN via the [IAM dashboard](https://console.aws.amazon.com/iam/home#/users), or by running `aws iam get-user` on a machine that is authenticated as the IAM user (or `AWS_ACCESS_KEY_ID=*** AWS_SECRET_ACCESS_KEY=*** aws iam get-user` on any machine, using the credentials of the IAM user). The ARN should look similar to `arn:aws:iam::764403040417:user/my-username`.
87+
88+
1. Set the following environment variables:
89+
90+
```bash
91+
CREATOR_AWS_ACCESS_KEY_ID=*** # access key ID for the IAM user that created the cluster
92+
CREATOR_AWS_SECRET_ACCESS_KEY=*** # secret access key for the IAM user that created the cluster
93+
NEW_USER_ARN=*** # ARN of the IAM user to grant access to
94+
CLUSTER_NAME=*** # the name of your cortex cluster (will be "cortex" unless you specified a different name in your cluster configuration file)
95+
CLUSTER_REGION=*** # the region of your cortex cluster
96+
```
97+
98+
1. Run the following command:
99+
100+
```bash
101+
AWS_ACCESS_KEY_ID=$CREATOR_AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY=$CREATOR_AWS_SECRET_ACCESS_KEY eksctl create iamidentitymapping --region $CLUSTER_REGION --cluster $CLUSTER_NAME --arn $NEW_USER_ARN --group system:masters --username $NEW_USER_ARN
102+
```
103+
104+
1. To revoke access in the future, run:
105+
106+
```bash
107+
AWS_ACCESS_KEY_ID=$CREATOR_AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY=$CREATOR_AWS_SECRET_ACCESS_KEY eksctl delete iamidentitymapping --region $CLUSTER_REGION --cluster $CLUSTER_NAME --arn $NEW_USER_ARN --all
108+
```

manager/debug.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
CORTEX_VERSION_MINOR=master
18+
1719
debug_out_path="$1"
1820
mkdir -p "$(dirname "$debug_out_path")"
1921

@@ -23,6 +25,7 @@ if ! eksctl utils describe-stacks --cluster=$CORTEX_CLUSTER_NAME --region=$CORTE
2325
fi
2426

2527
eksctl utils write-kubeconfig --cluster=$CORTEX_CLUSTER_NAME --region=$CORTEX_REGION | grep -v "saved kubeconfig as" | grep -v "using region" | grep -v "eksctl version" || true
28+
out=$(kubectl get pods 2>&1 || true); if [[ "$out" == *"must be logged in to the server"* ]]; then echo "error: your aws iam user does not have access to this cluster; to grant access, see https://docs.cortex.dev/v/${CORTEX_VERSION_MINOR}/miscellaneous/security#running-cortex-cluster-commands-from-different-iam-users"; exit 1; fi
2629

2730
echo -n "gathering cluster data"
2831

manager/info.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
set -eo pipefail
1818

19+
CORTEX_VERSION_MINOR=master
20+
1921
function get_operator_endpoint() {
2022
kubectl -n=istio-system get service ingressgateway-operator -o json | tr -d '[:space:]' | sed 's/.*{\"hostname\":\"\(.*\)\".*/\1/'
2123
}
@@ -34,6 +36,7 @@ if ! eksctl utils describe-stacks --cluster=$CORTEX_CLUSTER_NAME --region=$CORTE
3436
fi
3537

3638
eksctl utils write-kubeconfig --cluster=$CORTEX_CLUSTER_NAME --region=$CORTEX_REGION | grep -v "saved kubeconfig as" | grep -v "using region" | grep -v "eksctl version" || true
39+
out=$(kubectl get pods 2>&1 || true); if [[ "$out" == *"must be logged in to the server"* ]]; then echo "error: your aws iam user does not have access to this cluster; to grant access, see https://docs.cortex.dev/v/${CORTEX_VERSION_MINOR}/miscellaneous/security#running-cortex-cluster-commands-from-different-iam-users"; exit 1; fi
3740

3841
operator_endpoint=$(get_operator_endpoint)
3942
api_load_balancer_endpoint=$(get_api_load_balancer_endpoint)

manager/install.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
set -eo pipefail
1818

1919
export CORTEX_VERSION=master
20+
export CORTEX_VERSION_MINOR=master
2021
EKSCTL_TIMEOUT=45m
2122
mkdir /workspace
2223

@@ -199,6 +200,7 @@ function main() {
199200
fi
200201

201202
eksctl utils write-kubeconfig --cluster=$CORTEX_CLUSTER_NAME --region=$CORTEX_REGION | grep -v "saved kubeconfig as" | grep -v "using region" | grep -v "eksctl version" || true
203+
out=$(kubectl get pods 2>&1 || true); if [[ "$out" == *"must be logged in to the server"* ]]; then echo "error: your aws iam user does not have access to this cluster; to grant access, see https://docs.cortex.dev/v/${CORTEX_VERSION_MINOR}/miscellaneous/security#running-cortex-cluster-commands-from-different-iam-users"; exit 1; fi
202204

203205
# pre-download images on cortex cluster up
204206
if [ "$arg1" != "--update" ]; then

manager/refresh.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
set -e
1818

19+
CORTEX_VERSION_MINOR=master
20+
1921
cluster_config_out_path="$1"
2022
mkdir -p "$(dirname "$cluster_config_out_path")"
2123

@@ -25,6 +27,7 @@ if ! eksctl utils describe-stacks --cluster=$CORTEX_CLUSTER_NAME --region=$CORTE
2527
fi
2628

2729
eksctl utils write-kubeconfig --cluster=$CORTEX_CLUSTER_NAME --region=$CORTEX_REGION | grep -v "saved kubeconfig as" | grep -v "using region" | grep -v "eksctl version" || true
30+
out=$(kubectl get pods 2>&1 || true); if [[ "$out" == *"must be logged in to the server"* ]]; then echo "error: your aws iam user does not have access to this cluster; to grant access, see https://docs.cortex.dev/v/${CORTEX_VERSION_MINOR}/miscellaneous/security#running-cortex-cluster-commands-from-different-iam-users"; exit 1; fi
2831

2932
kubectl get -n=default configmap cluster-config -o yaml >> cluster_configmap.yaml
3033
python refresh_cluster_config.py cluster_configmap.yaml tmp_cluster_config.yaml

0 commit comments

Comments
 (0)