graphrbac

package
v0.0.0-...-86c76a3 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddClientSecret

func AddClientSecret(ctx context.Context, objID string) (autorest.Response, error)

AddClientSecret adds a secret to the specified AAD app

func CreateADApplication

func CreateADApplication(ctx context.Context) (graphrbac.Application, error)

CreateADApplication creates an Azure Active Directory (AAD) application

func CreateADGroup

func CreateADGroup(ctx context.Context) (graphrbac.ADGroup, error)

CreateADGroup creates an Active Directory group

Example
ctx := context.Background()

group, err := CreateADGroup(ctx)
if err != nil {
	util.PrintAndLog(err.Error())
}
util.PrintAndLog("ad group created")

if !config.KeepResources() {
	_, err = DeleteADGroup(ctx, *group.ObjectID)
	if err != nil {
		util.PrintAndLog(err.Error())
	}
	util.PrintAndLog("ad group deleted")
}
Output:

ad group created
ad group deleted if KeepResources=false

func CreateServicePrincipal

func CreateServicePrincipal(ctx context.Context, appID string) (graphrbac.ServicePrincipal, error)

CreateServicePrincipal creates a service principal associated with the specified application.

Example
var groupName = config.GenerateGroupName("GraphRBAC")
config.SetGroupName(groupName)

ctx := context.Background()

app, err := CreateADApplication(ctx)
if err != nil {
	util.PrintAndLog(err.Error())
}
util.PrintAndLog("ad app created")

sp, err := CreateServicePrincipal(ctx, *app.AppID)
if err != nil {
	util.PrintAndLog(err.Error())
}
util.PrintAndLog("service principal created")

_, err = AddClientSecret(ctx, *app.ObjectID)
if err != nil {
	util.PrintAndLog(err.Error())
}
util.PrintAndLog("added client secret")

_, err = resources.CreateGroup(ctx, config.GroupName())
if err != nil {
	util.PrintAndLog(err.Error())
}
util.PrintAndLog("created resource group")

list, err := authorization.ListRoleDefinitions(ctx, "roleName eq 'Contributor'")
if err != nil {
	util.PrintAndLog(err.Error())
}
util.PrintAndLog("list contributor roledefs at group scope")

_, err = authorization.AssignRole(ctx, *sp.ObjectID, *list.Values()[0].ID)
if err != nil {
	util.PrintAndLog(err.Error())
}
util.PrintAndLog("assigned new principal to first contributor role")

if !config.KeepResources() {
	_, err = resources.DeleteGroup(ctx, config.GroupName())
	if err != nil {
		util.PrintAndLog(err.Error())
	}

	_, err = DeleteADApplication(ctx, *app.ObjectID)
	if err != nil {
		util.PrintAndLog(err.Error())
	}
}
Output:

ad app created
service principal created
added client secret
created resource group
list contributor roledefs at group scope
assigned new principal to first contributor role

func DeleteADApplication

func DeleteADApplication(ctx context.Context, appObjID string) (autorest.Response, error)

DeleteADApplication deletes the specified AAD application

func DeleteADGroup

func DeleteADGroup(ctx context.Context, groupObjID string) (autorest.Response, error)

DeleteADGroup deletes the specified Active Directory group

func GetCurrentUser

func GetCurrentUser(ctx context.Context) (graphrbac.User, error)

GetCurrentUser gets the Azure Active Directory object of the current signed in user

func GetServicePrincipalObjectID

func GetServicePrincipalObjectID(ctx context.Context, clientID string) (string, error)

GetServicePrincipalObjectID returns the service principal object ID for the specified client ID.

Types

This section is empty.

Jump to

Keyboard shortcuts

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