Codify SQL Review Policies with Bytebase API
Bytebase is a database DevSecOps platform designed for developers, security, DBA, and platform engineering teams. While it offers an intuitive GUI for managing database schema changes and access control, some teams may want to integrate Bytebase into their existing DevOps platforms using the Bytebase API.
This tutorial will guide you through configuring SQL review rules using the Bytebase API. This approach allows you to manage SQL review rules as code within your repository, enabling DBAs or platform engineering teams to apply them to Bytebase as needed.
Prerequisites
- Docker installed
- Node.js >= v18
Start Bytebase
Make sure your Docker daemon is running. Copy and paste the commands to start Bytebase.
Bytebase is now running via Docker, and you can access it via localhost:8080
. Register the first admin account which will be granted Workspace Admin
.
Create Service Account
-
Log in as the admin user, and go to Security & Policy > Users & Groups. Click + Add User, fill in with
api-example
, choose theDBA
role that is sufficient for this tutorial and click Confirm. -
Find the newly created service account and click on Copy Service Key. We will use this token to authenticate the API calls.
Obtain the Access Token
-
Go to Bytebase API Example repo and clone it.
-
Go to subfolder
sql-review
, and follow the instructions in theREADME.md
to run the scripts. replace thebytebase_url
,bytebase_account
,bytebase_password
with your own values. Then you will get abytebase_token
looks likeey....9V8s
.
Configure SQL Review Policies
-
Continue following the
README.md
to run the scripts. -
In the Bytebase console, navigate to CI/CD > SQL Review to see the applied SQL review rules. You may click Edit to change the rules.
-
To delete the SQL review rules, use the following commands:
Attach SQL Review Policies to Resources
You may notice that the SQL review rules are not applied to any resources yet from the above screenshot. In Bytebase, the SQL review rules can be applied to the environments
or projects
. Project-level rules take precedence over environment-level rules.
-
Follow the
README.md
to run the scripts to apply the SQL review rules to environments. -
Continue with the
README.md
to apply the SQL review rules to projects. -
On the CI/CD > SQL Review page, you will see the SQL review rules are applied to environments and projects.
-
Go to Environments page, click Test environment to see the applied SQL review rules.
-
Go to
Sample Project
page, click Setting on the left sidebar to see the applied the SQL review rules. -
To detach SQL review policies from environments and projects, use the following commands:
Summary
Congratulations! You can now codify SQL review rules using the Bytebase API, in addition to the Bytebase GUI, making SQL review policy as code a reality.