azureaccess

package
v0.186.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package azureaccess asks Azure Resource Manager whether the credentials in the environment can read a subscription, and which actions they hold on it.

The first question is asked by two callers: `draugr doctor`, to say whether a declared subscription can be reached, and the prowler scanner, before Prowler runs. The second is the scanner's. Prowler's Azure service base class discards the exceptions its worker threads raise, so a denial inside a service can leave no log line, and the answer has to come from somewhere other than its output.

Prowler has no flag for Azure's whole default credential chain: each of its flags keeps one credential and excludes the others. AuthFlag chooses the flag, and New builds the credential that flag leaves Prowler with, which is what makes the answer about the scan rather than about this process.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoCredentials = errors.New("no usable Azure credentials found: run `az login`, set " +
	"AZURE_CLIENT_ID, AZURE_TENANT_ID and AZURE_CLIENT_SECRET, or run where a managed identity is attached")

ErrNoCredentials is a machine with no Azure credential that yields a token.

View Source
var ErrRefused = errors.New("the credentials may not list their permissions on the subscription")

ErrRefused is a permissions question Azure refused to answer for these credentials.

Functions

func AuthFlag

func AuthFlag(getenv func(string) string) string

AuthFlag is the Prowler flag for the credential the environment declares.

A service principal's three variables are the only form --sp-env-auth accepts, and Prowler refuses to start with one missing. IDENTITY_ENDPOINT is what App Service, Functions, Container Apps and Arc set for a managed identity. Everything else is --az-cli-auth, which leaves Prowler the sign-in `az login` holds, a federated one and `az login --identity` included, and workload identity where AZURE_FEDERATED_TOKEN_FILE is set. A virtual machine's managed identity sets no variable, so it is reached with `az login --identity`.

func Denied

func Denied(grants []Permission, actions []string) []string

Denied returns the actions, in the order given, that none of the grants allow. Deny assignments are outside the answer Azure gives, and Prowler's log catches those.

func HoldsAnAction

func HoldsAnAction(grants []Permission) bool

HoldsAnAction reports whether any grant allows anything. Azure answers an empty list for credentials with no role on a subscription they can still see.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client asks Azure Resource Manager with one credential.

func New

func New(_ context.Context) (*Client, error)

New builds the credential AuthFlag selects from the environment and returns a Client that asks with it.

func NewWith

func NewWith(client *http.Client, endpointURL string, token TokenFunc) *Client

NewWith returns a Client asking endpointURL through client, with tokens from token.

func (*Client) Permissions

func (c *Client) Permissions(ctx context.Context, id string) ([]Permission, error)

Permissions lists the credentials' grants on the subscription, every page of them.

func (*Client) Subscription

func (c *Client) Subscription(ctx context.Context, id string) (Subscription, error)

Subscription asks for the subscription, which needs Microsoft.Resources/subscriptions/read.

A subscription the credentials hold no role on and one that does not exist are one answer here, because neither says which: the error says both.

type Permission

type Permission struct {
	// Actions are the action patterns the role allows.
	Actions []string `json:"actions"`
	// NotActions are the patterns excluded from this entry's Actions. They take nothing away from
	// another entry.
	NotActions []string `json:"notActions"`
	// DataActions are the data-plane patterns the role allows, which the checks' control-plane reads do
	// not use.
	DataActions []string `json:"dataActions"`
}

Permission is one role's grant on a subscription, as Microsoft.Authorization/permissions returns it. An action is held when one entry's Actions match it and that entry's NotActions do not.

type Reader

type Reader interface {
	// Subscription returns the subscription, or an error naming it when the credentials cannot read it.
	Subscription(ctx context.Context, id string) (Subscription, error)
	// Permissions lists the credentials' grants on the subscription. ErrRefused says they may not ask.
	Permissions(ctx context.Context, id string) ([]Permission, error)
}

Reader asks Azure Resource Manager about a subscription.

type Subscription

type Subscription struct {
	// ID is the subscription's GUID.
	ID string
	// Name is its display name.
	Name string
}

Subscription is what Azure says about a subscription the credentials can read.

type TokenFunc

type TokenFunc func(ctx context.Context) (string, error)

TokenFunc returns a bearer token for Azure Resource Manager.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL