Azure / Azure/api-management-policy-snippets

APIM manager API policy creation using azuredevops pipeline

Open
#120 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
399
Forks
170
PR merge metrics
No merged PRs in 30d

Description

Looking for a way to automate the custom policy creation across the scope of api and operations idempoently in Azure API manager.

The pipeline input is as below

stages:
- template: api-ops-pipeline.yaml
parameters:
policyList:
- name: rate_limit_ip
scope: api
apiname: test-policy, test2-policy

- name: IPfilter
scope: operation
ipAddressesFrom: xxxxx
ipAddressesTo: xxxxxxx
operationname: getxxx, getyy, getzz

policy.xml template




$(rate-limit-by_ip)
$(rate-limit-by_subkey)
$(rate-limit-by_DevID)
$(rate-limit-by_ip)+$(rate-limit-by_DevID)









$(rate-limit-by-ip_error)
$(rate-limit-by_DevID_error)


As a first task, we have to create the custom initial_policy.xml file in different scenarios as per the policy list provided by the app team and need to generate it in accordance with the scope of the policy (might be specific to api or might be specifically to a single operation in it or multiple operation in it)

We may have the different combination as below and, when the scope is only to operations, it should first check whether the same policy is applied in its parent api or APIM instance level itself.

Combinations

- rate-limit-by_ip
- rate-limit-by_subkey
- rate-limit-by_DevID
- rate-limit-by_ip+ rate-limit-by_DevID
- Or any custom combination with on error properties as well

Once the above step is completed, in the above created custom initial_policy.xml , the users inputs parameters are replaced (threshold, time etc..) and final_policy.xml will be created.

Then , finally it can be applied to the scope given, (might be to api/apis or operation/operations)

The pipeline template drafyed as below.

jobs:
- job: api
displayName: 'api policy'
variables:
- group: api_policy
workspace:
clean: all
pool:
name: xxxxxxx
steps:
- ${{ each policy in parameters.policyList }}:
- ${{ if and(eq(policy.name, 'rate_limit_ip'), eq(policy.scope, 'api') ) }}:
- bash: |
apiName=${{ policy.Name }}
echo "##vso[task.setvariable variable=apiName]$apiName"
xxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxx
name: Resolve_variable

- task: qetza.replacetokens.replacetokens-task.replacetokens@3
displayName: 'create initial xml'
inputs:
rootDirectory: '$(System.DefaultWorkingDirectory)/policy'
targetFiles: initial_policy.xml
tokenPrefix: '${'
tokenSuffix: '}$'
enableTelemetry: false
continueOnError: true

- task: qetza.replacetokens.replacetokens-task.replacetokens@3
displayName: 'create final xml'
inputs:
rootDirectory: '$(System.DefaultWorkingDirectory)/policy'
targetFiles: final_policy.xml
tokenPrefix: '${'
tokenSuffix: '}$'
enableTelemetry: false
continueOnError: true

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the proposed api-ops-pipeline.yaml template and the initial_policy.xml and final_policy.xml templates described in the issue. Map the policyList scopes, combinations, and parameter replacement flow before deciding where the pipeline integration belongs. Done means policies are generated idempotently and applied to the requested APIs or operations while respecting inherited policies.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure
Domain
api, devops
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.