Join our Newsletter — 33% off our NHI Course
Authentication, Authorisation & Trust

EXECUTE AS

← Back to Glossary
By NHI Mgmt Group Updated November 9, 2026 Domain: Authentication, Authorisation & Trust

EXECUTE AS is a SQL Server permission context feature that runs a module or session under a specified execution principal. It is used for permission elevation or impersonation within database code, so the caller can act with the rights of a login, user or owner rather than its own.

What EXECUTE AS Does in SQL Server

EXECUTE AS changes the execution context of a database module or session so code runs as a chosen principal rather than the caller. That makes it a controlled form of impersonation inside SQL Server, useful when a stored procedure, trigger, or other module needs rights the invoker should not have directly.

The key idea is separation between who starts the action and whose permissions are used to complete it. That distinction matters because it can simplify application design, but it also means security decisions are being made inside the database engine, not just in application code.

Why Permission Context Matters

Permission context determines which tables, routines, objects, or administrative actions the code can reach. With EXECUTE AS, a module may gain access that would otherwise be blocked by normal least-privilege boundaries, which can be helpful for encapsulating sensitive operations behind a narrow interface.

This is why the feature is often used for privilege shaping rather than broad privilege grant. The database can expose a limited entry point to callers while the module itself operates with elevated rights under a specified principal, reducing the need to hand out direct object permissions to every user or application component.

How EXECUTE AS Differs from Direct Caller Rights

Under a normal call, SQL Server evaluates access using the caller’s identity and permissions. Under EXECUTE AS, the effective permissions may switch to a login, database user, or owner context, which can alter what the same statement can do without changing the SQL text itself.

That makes the feature a security boundary as well as a convenience mechanism. The same stored procedure can be harmless or highly privileged depending on the execution context, so review of the code body alone is not enough, the privilege model around it must also be understood.

Where EXECUTE AS Becomes Dangerous

The feature is dangerous when the impersonated context is broader than the module truly needs, when ownership chains hide unintended access, or when an attacker can influence a module that runs with elevated rights. In those cases, a routine intended to simplify access can become a path to privilege escalation or unauthorized data access.

It is also sensitive because the effective rights may outlive the original caller’s intended scope for that transaction or session. If the module performs dynamic SQL, reaches protected metadata, or touches administrative objects, a small mistake in permission design can turn a local code path into a high-impact control failure.

Typical Security Controls Around EXECUTE AS

Practitioners usually treat this feature as something to document, constrain, and review rather than use casually. The safest pattern is to keep the impersonated principal as limited as possible, understand whether ownership chaining is doing the real work, and verify which objects are reachable under the alternate context.

Good practice also includes testing modules with and without the impersonated context, checking for unintended elevation paths, and reviewing whether module signing, explicit grants, or application-layer authorization would be clearer. For broader identity and access control context, the same least-privilege principles described in NIST SP 800-53 Rev 5 Security and Privacy Controls and NIST Cybersecurity Framework 2.0 help frame why impersonation should be tightly governed. When database modules are part of a broader attack path, adversary techniques around privilege escalation and credential abuse are well mapped in MITRE ATT&CK Enterprise Matrix.

Risk and Threat Considerations

EXECUTE AS can concentrate privilege in ways that are easy to overlook, especially when a module is reused across many callers. If the elevated context is too broad, an attacker who can influence the module may inherit rights far beyond the caller’s own access.

Failure mechanism: The code executes successfully because SQL Server evaluates permissions against the impersonated principal, which can bypass the restrictions that would normally block the caller.

Impact: A compromised or misused module can expose sensitive data, alter protected objects, or create a privilege-escalation path that is hard to spot during routine application testing.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

MITRE ATT&CK addresses the attack and risk surface, while NIST SP 800-53 Rev 5 and NIST CSF 2.0 set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
NIST SP 800-53 Rev 5AC-6 — Least PrivilegeEXECUTE AS changes effective rights, so least-privilege design directly governs the impersonated context.
IA-5 — Authenticator ManagementPermission-context changes often rely on credentials and principals whose lifecycle must be controlled.
AU-6 — Audit Record Review, Analysis, and ReportingImpersonation requires monitoring to confirm who acted under which effective context.
Recommendation — Limit impersonated modules to the minimum permissions needed and review elevated database paths regularly. Protect and rotate credentials tied to privileged database principals used in impersonation flows. Review audit events for module execution under alternate principals and investigate unexpected privilege use.
NIST CSF 2.0PR.AA-05 — Least PrivilegeThe feature is an access-control mechanism whose safe use depends on restricted privilege.
Recommendation — Apply least-privilege rules to any database module that runs under an alternate execution context.
MITRE ATT&CKT1068 — Exploitation for Privilege EscalationOverbroad impersonation can be abused to gain permissions beyond the original caller.
Recommendation — Map abnormal EXECUTE AS abuse to privilege-escalation detections and hunt for unauthorized elevation paths.

Practitioner Guidance

Governance implication: Treat EXECUTE AS as a privileged design choice, not a default implementation detail. Assign ownership for each impersonated module, document why the alternate context is required, and review whether the chosen principal still matches the minimum access needed as the application evolves.

What to watch for: Pay special attention to dynamic SQL, nested module calls, and routines that cross trust boundaries, because those are the places where the effective permission set can become broader than intended. The safer pattern is to be explicit about who is meant to act and what that context can reach.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Reviewed and updated by the NHIMG editorial team on November 9, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org