Skip to main content

Authentication Rule Configuration Object

Manages authentication rules that enforce identity-based policy for network traffic in Palo Alto Networks Strata Cloud Manager.

Class Overview​

The AuthenticationRule class inherits from BaseObject and provides CRUD operations plus rule positioning for authentication rules that enforce identity-based policy for traffic flowing between zones, addresses, and users.

Methods​

MethodDescriptionParametersReturn Type
create()Creates a new authentication ruledata: Dict[str, Any], rulebase: strAuthenticationRuleResponseModel
get()Retrieves a rule by IDobject_id: str, rulebase: strAuthenticationRuleResponseModel
update()Updates an existing rulerule: AuthenticationRuleUpdateModelAuthenticationRuleResponseModel
delete()Deletes a ruleobject_id: str, rulebase: strNone
list()Lists rules with filteringfolder: str, rulebase: strList[AuthenticationRuleResponseModel]
fetch()Gets rule by name and containername: str, folder: strAuthenticationRuleResponseModel
move()Moves rule within rulebaserule_id: UUID, data: Dict[str, Any]None

Model Attributes​

AttributeTypeRequiredDefaultDescription
namestrYesNoneName of rule. Pattern: ^[a-zA-Z0-9_ \.-]+$
idUUIDYes*NoneUnique identifier (*response/update only)
disabledboolNoFalseWhether the rule is disabled
descriptionstrNoNoneRule description
tagList[str]No[]Associated tags
from_List[str]No["any"]Source zones
sourceList[str]No["any"]Source addresses
negate_sourceboolNoFalseNegate source addresses
source_userList[str]No["any"]Source users/groups
source_hipList[str]No["any"]Source Host Integrity Profiles
to_List[str]No["any"]Destination zones
destinationList[str]No["any"]Destination addresses
negate_destinationboolNoFalseNegate destination addresses
destination_hipList[str]No["any"]Destination Host Integrity Profiles
serviceList[str]No["any"]Allowed services
categoryList[str]No["any"]URL categories
authentication_enforcementstrNoNoneAuthentication profile name
hip_profilesList[str]NoNoneSource Host Integrity Profiles
group_tagstrNoNoneGroup tag
timeoutintNoNoneAuth session timeout in minutes (1-1440)
log_settingstrNoNoneLog forwarding profile
log_authentication_timeoutboolNoFalseLog authentication timeouts
rulebaseAuthenticationRuleRulebaseNoNoneWhich rulebase (pre/post)
folderstrNo**NoneFolder location. Max 64 chars
snippetstrNo**NoneSnippet location. Max 64 chars
devicestrNo**NoneDevice location. Max 64 chars

* Only required for response and update models ** Exactly one container (folder, snippet, or device) must be provided for create operations

Exceptions​

ExceptionHTTP CodeDescription
InvalidObjectError400Invalid rule data or format
MissingQueryParameterError400Missing required parameters
NameNotUniqueError409Rule name already exists
ObjectNotPresentError404Rule not found
ReferenceNotZeroError409Rule still referenced
AuthenticationError401Authentication failed
ServerError500Internal server error

Basic Configuration​

from scm.client import Scm

client = Scm(
client_id="your_client_id",
client_secret="your_client_secret",
tsg_id="your_tsg_id"
)

rules = client.authentication_rule

Methods​

List Authentication Rules​

filtered_rules = client.authentication_rule.list(
folder='Texas',
rulebase='pre',
service=['service-http', 'service-https']
)

for rule in filtered_rules:
print(f"Name: {rule.name}")
print(f"Auth enforcement: {rule.authentication_enforcement}")
print(f"Timeout: {rule.timeout}")

Filtering responses:

exact_rules = client.authentication_rule.list(
folder='Texas',
rulebase='pre',
exact_match=True
)

combined_filters = client.authentication_rule.list(
folder='Texas',
rulebase='pre',
exact_match=True,
exclude_folders=['All'],
exclude_snippets=['default'],
exclude_devices=['DeviceA']
)

Controlling pagination with max_limit:

client.authentication_rule.max_limit = 4000

all_rules = client.authentication_rule.list(folder='Texas', rulebase='pre')

Fetch an Authentication Rule​

rule = client.authentication_rule.fetch(
name="auth-web-traffic",
folder="Texas",
rulebase="pre"
)
print(f"Found rule: {rule.name}")

Create an Authentication Rule​

# Basic authentication rule with auth enforcement
basic_rule = {
"name": "auth-web-traffic",
"folder": "Texas",
"from_": ["trust"],
"to_": ["untrust"],
"source": ["internal-net"],
"destination": ["any"],
"service": ["service-http", "service-https"],
"authentication_enforcement": "auth-profile-1",
"log_authentication_timeout": True
}
created_rule = client.authentication_rule.create(basic_rule, rulebase="pre")

# Authentication rule with HIP profiles
hip_rule = {
"name": "auth-hip-rule",
"folder": "Texas",
"from_": ["trust"],
"to_": ["untrust"],
"source_user": ["domain\\jsmith", "domain\\jdoe"],
"source": ["any"],
"destination": ["any"],
"service": ["any"],
"category": ["any"],
"hip_profiles": ["hip-compliant", "hip-patched"],
"authentication_enforcement": "strict-auth-profile",
"group_tag": "compliance-group",
"tag": ["Compliance", "HIP"]
}
hip_created = client.authentication_rule.create(hip_rule, rulebase="pre")

Update an Authentication Rule​

existing_rule = client.authentication_rule.fetch(
name="auth-web-traffic",
folder="Texas",
rulebase="pre"
)

existing_rule.description = "Updated authentication rule for web traffic"
existing_rule.timeout = 120
existing_rule.authentication_enforcement = "updated-auth-profile"

updated_rule = client.authentication_rule.update(existing_rule, rulebase="pre")

Delete an Authentication Rule​

client.authentication_rule.delete("123e4567-e89b-12d3-a456-426655440000", rulebase="pre")

Move an Authentication Rule​

# Move rule to top of rulebase
client.authentication_rule.move(rule.id, {
"destination": "top",
"rulebase": "pre"
})

# Move rule before another rule
client.authentication_rule.move(rule.id, {
"destination": "before",
"rulebase": "pre",
"destination_rule": "987fcdeb-54ba-3210-9876-fedcba098765"
})

# Move rule after another rule
client.authentication_rule.move(rule.id, {
"destination": "after",
"rulebase": "pre",
"destination_rule": "987fcdeb-54ba-3210-9876-fedcba098765"
})

Get an Authentication Rule by ID​

rule_by_id = client.authentication_rule.get(rule.id, rulebase="pre")
print(f"Retrieved rule: {rule_by_id.name}")
print(f"Authentication enforcement: {rule_by_id.authentication_enforcement}")

Use Cases​

Committing Changes​

result = client.commit(
folders=["Texas"],
description="Updated authentication rules",
sync=True,
timeout=300
)
print(f"Commit job ID: {result.job_id}")

Monitoring Jobs​

job_status = client.get_job_status(result.job_id)
print(f"Job status: {job_status.data[0].status_str}")

recent_jobs = client.list_jobs(limit=10)
for job in recent_jobs.data:
print(f"Job {job.id}: {job.type_str} - {job.status_str}")

Error Handling​

from scm.exceptions import (
InvalidObjectError,
MissingQueryParameterError,
NameNotUniqueError,
ObjectNotPresentError,
ReferenceNotZeroError
)

try:
rule_config = {
"name": "test-auth-rule",
"folder": "Texas",
"from_": ["trust"],
"to_": ["untrust"],
"source": ["internal-net"],
"destination": ["any"],
"service": ["application-default"],
"authentication_enforcement": "auth-profile-1"
}
new_rule = client.authentication_rule.create(rule_config, rulebase="pre")
client.authentication_rule.move(new_rule.id, {
"destination": "top",
"rulebase": "pre"
})
result = client.commit(
folders=["Texas"],
description="Added authentication rule",
sync=True
)
status = client.get_job_status(result.job_id)

except InvalidObjectError as e:
print(f"Invalid rule data: {e.message}")
except NameNotUniqueError as e:
print(f"Rule name already exists: {e.message}")
except ObjectNotPresentError as e:
print(f"Rule not found: {e.message}")
except ReferenceNotZeroError as e:
print(f"Rule still in use: {e.message}")
except MissingQueryParameterError as e:
print(f"Missing parameter: {e.message}")