mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-01-07 19:46:53 +00:00
Support data plane RBAC for E2E tests. (#2176)
* Acquire token for NoSQL account prior to running tests. * Change client id to user assigned managed identity. * Change to use managed identity. Add token variables for gremlin and tables. * Add RBAC details to test README. * Add token for SQL readonly database. Skip resource token tests when RBAC enabled. * Use hardcoded account name for sql readonly. * Use specific tag for sql readonly. * Remove comment.
This commit is contained in:
@@ -8,12 +8,12 @@ The tests run in [Playwright](https://playwright.dev/), using the official Playw
|
||||
|
||||
To run all the tests, you need:
|
||||
|
||||
* A CosmosDB Account using the Cassandra API
|
||||
* A CosmosDB Account using the Gremlin API
|
||||
* A CosmosDB Account using the MongoDB API, API version 6.0
|
||||
* A CosmosDB Account using the MongoDB API, API version 3.2
|
||||
* A CosmosDB Account using the NoSQL API
|
||||
* A CosmosDB Account using the Tables API
|
||||
- A CosmosDB Account using the Cassandra API
|
||||
- A CosmosDB Account using the Gremlin API
|
||||
- A CosmosDB Account using the MongoDB API, API version 6.0
|
||||
- A CosmosDB Account using the MongoDB API, API version 3.2
|
||||
- A CosmosDB Account using the NoSQL API
|
||||
- A CosmosDB Account using the Tables API
|
||||
|
||||
Each Account must have at least 1000 RU/s of throughput available for new databases/collections/etc.
|
||||
The tests create new databases/keyspaces/etc. for each test, and delete them when the test is done.
|
||||
@@ -62,10 +62,10 @@ Do you want to continue? (y/n):
|
||||
|
||||
This prompt shows:
|
||||
|
||||
* The resources that will be deployed, in this case, all of them. You can filter to deploy only a subset by specifying the `-ResourceTypes` parameter. For example `-ResourceTypes @("cassandra", "sql")`.
|
||||
* The location the resources will be deployed to, `West US 3` in this case.
|
||||
* The resource group that will be used, `ashleyst-e2e-testing` in this case.
|
||||
* The subscription that will be used.
|
||||
- The resources that will be deployed, in this case, all of them. You can filter to deploy only a subset by specifying the `-ResourceTypes` parameter. For example `-ResourceTypes @("cassandra", "sql")`.
|
||||
- The location the resources will be deployed to, `West US 3` in this case.
|
||||
- The resource group that will be used, `ashleyst-e2e-testing` in this case.
|
||||
- The subscription that will be used.
|
||||
|
||||
Once you confirm, the resources will be deployed using Azure PowerShell and the Bicep templates in the `resources` directory. The script will wait for all the deployments to complete before exiting.
|
||||
|
||||
@@ -76,18 +76,18 @@ You can re-run this script at any time to update the resources, if the Bicep tem
|
||||
Before running the tests, you need to configure your environment to specify the accounts to use for testing.
|
||||
The following environment variables are used:
|
||||
|
||||
* `DE_TEST_RESOURCE_GROUP` - The resource group to use for testing. This should be the same resource group that the resources were deployed to.
|
||||
* `DE_TEST_SUBSCRIPTION_ID` - The subscription ID to use for testing. This should be the same subscription that the resources were deployed to.
|
||||
* `DE_TEST_ACCOUNT_PREFIX` - If you used the default naming scheme provided by the `deploy.ps1` script, this should be your Windows username (or whatever value you passed in for the `-ResourcePrefix` argument when deploying). This is used to find the accounts that were deployed.
|
||||
- `DE_TEST_RESOURCE_GROUP` - The resource group to use for testing. This should be the same resource group that the resources were deployed to.
|
||||
- `DE_TEST_SUBSCRIPTION_ID` - The subscription ID to use for testing. This should be the same subscription that the resources were deployed to.
|
||||
- `DE_TEST_ACCOUNT_PREFIX` - If you used the default naming scheme provided by the `deploy.ps1` script, this should be your Windows username (or whatever value you passed in for the `-ResourcePrefix` argument when deploying). This is used to find the accounts that were deployed.
|
||||
|
||||
In the event you didn't use the `deploy.ps1` script, you can specify the accounts directly using the following environment variables:
|
||||
|
||||
* `DE_TEST_ACCOUNT_NAME_CASSANDRA` - The name of the CosmosDB Account using the Cassandra API.
|
||||
* `DE_TEST_ACCOUNT_NAME_GREMLIN` - The name of the CosmosDB Account using the Gremlin API.
|
||||
* `DE_TEST_ACCOUNT_NAME_MONGO` - The name of the CosmosDB Account using the MongoDB API, API version 6.0.
|
||||
* `DE_TEST_ACCOUNT_NAME_MONGO32` - The name of the CosmosDB Account using the MongoDB API, API version 3.2.
|
||||
* `DE_TEST_ACCOUNT_NAME_SQL` - The name of the CosmosDB Account using the NoSQL API.
|
||||
* `DE_TEST_ACCOUNT_NAME_TABLES` - The name of the CosmosDB Account using the Tables API.
|
||||
- `DE_TEST_ACCOUNT_NAME_CASSANDRA` - The name of the CosmosDB Account using the Cassandra API.
|
||||
- `DE_TEST_ACCOUNT_NAME_GREMLIN` - The name of the CosmosDB Account using the Gremlin API.
|
||||
- `DE_TEST_ACCOUNT_NAME_MONGO` - The name of the CosmosDB Account using the MongoDB API, API version 6.0.
|
||||
- `DE_TEST_ACCOUNT_NAME_MONGO32` - The name of the CosmosDB Account using the MongoDB API, API version 3.2.
|
||||
- `DE_TEST_ACCOUNT_NAME_SQL` - The name of the CosmosDB Account using the NoSQL API.
|
||||
- `DE_TEST_ACCOUNT_NAME_TABLES` - The name of the CosmosDB Account using the Tables API.
|
||||
|
||||
If you used all the standard deployment scripts and naming scheme, you can set these environment variables using the following command:
|
||||
|
||||
@@ -152,6 +152,46 @@ The UI allows you to select a specific test to run and to see the results of the
|
||||
|
||||
See the [Playwright docs](https://playwright.dev/docs/running-tests) for more information on running tests.
|
||||
|
||||
### Testing with Data Plane RBAC Authentication
|
||||
|
||||
By default, the tests will use key based authentication to access the database accounts. For APIs that support data plane RBAC, the
|
||||
test can be configured to use that instead, by acquiring access tokens and setting them to environment variables:
|
||||
|
||||
```powershell
|
||||
# NoSQL API
|
||||
$ENV:NOSQL_TESTACCOUNT_TOKEN=az account get-access-token --scope "https://<account name>.documents.azure.com/.default" -o tsv --query accessToken
|
||||
|
||||
# NoSQL API (Readonly)
|
||||
$ENV:NOSQL_READONLY_TESTACCOUNT_TOKEN=az account get-access-token --scope "https://<account name>.documents.azure.com/.default" -o tsv --query accessToken
|
||||
|
||||
# Tables API
|
||||
$ENV:TABLE_TESTACCOUNT_TOKEN=az account get-access-token --scope "https://<account name>.documents.azure.com/.default" -o tsv --query accessToken
|
||||
|
||||
# Gremlin API
|
||||
$ENV:GREMLIN_TESTACCOUNT_TOKEN=az account get-access-token --scope "https://<account name>.documents.azure.com/.default" -o tsv --query accessToken
|
||||
```
|
||||
|
||||
When setting up test accounts to use dataplane RBAC, you will need to create custom role definitions with the following roles:
|
||||
|
||||
```txt
|
||||
# NoSQL API roles
|
||||
Microsoft.DocumentDB/databaseAccounts/readMetadata
|
||||
Microsoft.DocumentDB/databaseAccounts/sqlDatabases/*
|
||||
Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/*
|
||||
Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/items/*
|
||||
Microsoft.DocumentDB/databaseAccounts/throughputSettings/*
|
||||
|
||||
# Tables API roles
|
||||
Microsoft.DocumentDB/databaseAccounts/readMetadata
|
||||
Microsoft.DocumentDB/databaseAccounts/tables/*
|
||||
Microsoft.DocumentDB/databaseAccounts/throughputSettings/*
|
||||
|
||||
# Gremlin API roles
|
||||
Microsoft.DocumentDB/databaseAccounts/readMetadata
|
||||
Microsoft.DocumentDB/databaseAccounts/gremlin/*
|
||||
Microsoft.DocumentDB/databaseAccounts/throughputSettings/
|
||||
```
|
||||
|
||||
## Clean-up
|
||||
|
||||
Tests should clean-up after themselves if they succeed (and sometimes even when they fail).
|
||||
@@ -189,4 +229,4 @@ Are you sure you want to delete these resources? (y/n): y
|
||||
Cleaning SQL Account: ashleyst-e2e-sql
|
||||
Cleaning Database: t_db32_1722890547089
|
||||
Cleaning Mongo Account: ashleyst-e2e-mongo32
|
||||
```
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user