An Azure SQL Database supports semantic product search. An external model object named Ada2Embeddings calls an Azure OpenAI embedding endpoint by using a database scoped credential. Two database users were created WITHOUT LOGIN:
- embedding_refresh_svc is used by a nightly job that calls the external model to generate embeddings. The job inserts new rows and updates existing rows in dbo.ProductEmbeddings, and it never deletes rows.
- app_query_user serves interactive search. It reads the stored vectors from dbo.ProductEmbeddings and never calls the model.
Each principal must be able to do its work, and neither may hold any permission beyond that work.
| Design | embedding_refresh_svc | app_query_user |
|---|---|---|
| Design 1 | EXECUTE on EXTERNAL MODEL::Ada2Embeddings; REFERENCES on the database scoped credential; INSERT, UPDATE on dbo.ProductEmbeddings | SELECT on dbo.ProductEmbeddings |
| Design 2 | EXECUTE on EXTERNAL MODEL::Ada2Embeddings; REFERENCES on the database scoped credential; INSERT, UPDATE on dbo.ProductEmbeddings | SELECT on dbo.ProductEmbeddings; EXECUTE on EXTERNAL MODEL::Ada2Embeddings |
| Design 3 | REFERENCES on the database scoped credential; INSERT, UPDATE on dbo.ProductEmbeddings | SELECT on dbo.ProductEmbeddings |
| Design 4 | EXECUTE on EXTERNAL MODEL::Ada2Embeddings; REFERENCES on the database scoped credential; INSERT, UPDATE, DELETE on dbo.ProductEmbeddings | SELECT on dbo.ProductEmbeddings |
Which permission design should you implement?
Least privilege here means splitting the workload across two principals and giving each only what its task uses. The nightly refresh account must call the model, so it needs EXECUTE on the external model and REFERENCES on the credential, plus INSERT and UPDATE because it only adds and changes rows. The search user only reads stored vectors, so SELECT on the table is enough and it has no route to the external endpoint. Design 1 is the only design that lets both principals work without any extra permission.
- Not correct: Design 4. DELETE lets the refresh account remove data from the table, but the job only inserts and updates, so this permission exceeds its work.
- Not correct: Design 3. The nightly job needs EXECUTE on Ada2Embeddings to generate embeddings.
- Not correct: Design 2. Search reads the stored vectors directly, so EXECUTE on the external model exceeds the permissions app_query_user needs.
- Correct: Design 1. The refresh account gets EXECUTE on the model, REFERENCES on the credential, and INSERT and UPDATE on the table. The query user gets SELECT on the table to read the stored vectors.