DNS Security Profile Configuration Object
Table of Contents
- Overview
- Core Methods
- DNS Security Profile Model Attributes
- Exceptions
- Basic Configuration
- Usage Examples
- Managing Configuration Changes
- Error Handling
- Best Practices
- Full Script Examples
- Related Models
Overview
The DNSSecurityProfile
class provides functionality to manage DNS Security profiles in Palo Alto Networks' Strata
Cloud Manager. This class inherits from BaseObject
and provides methods for creating, retrieving, updating, and
deleting profiles that protect against DNS-based threats including botnet domains, malware, and phishing attempts.
Core Methods
Method | Description | Parameters | Return Type |
---|---|---|---|
create() |
Creates a new profile | data: Dict[str, Any] |
DNSSecurityProfileResponseModel |
get() |
Retrieves a profile by ID | object_id: str |
DNSSecurityProfileResponseModel |
update() |
Updates an existing profile | profile: DNSSecurityProfileUpdateModel |
DNSSecurityProfileResponseModel |
delete() |
Deletes a profile | object_id: str |
None |
list() |
Lists profiles with filtering | folder: str , **filters |
List[DNSSecurityProfileResponseModel] |
fetch() |
Gets profile by name and folder | name: str , folder: str |
DNSSecurityProfileResponseModel |
DNS Security Profile Model Attributes
Attribute | Type | Required | Description |
---|---|---|---|
name |
str | Yes | Profile name (max 63 chars) |
id |
UUID | Yes* | Unique identifier (*response only) |
description |
str | No | Profile description |
botnet_domains |
BotnetDomainsModel | No | Botnet domains configuration |
dns_security_categories |
List[CategoryEntry] | No | DNS security category settings |
lists |
List[ListEntry] | No | Custom domain lists |
sinkhole |
SinkholeSettings | No | Sinkhole configuration |
whitelist |
List[WhitelistEntry] | No | Whitelisted domains |
folder |
str | Yes** | Folder location (**one container required) |
snippet |
str | Yes** | Snippet location (**one container required) |
device |
str | Yes** | Device location (**one container required) |
Exceptions
Exception | HTTP Code | Description |
---|---|---|
InvalidObjectError |
400 | Invalid profile data or format |
MissingQueryParameterError |
400 | Missing required parameters |
NameNotUniqueError |
409 | Profile name already exists |
ObjectNotPresentError |
404 | Profile not found |
ReferenceNotZeroError |
409 | Profile still referenced |
AuthenticationError |
401 | Authentication failed |
ServerError |
500 | Internal server error |
Basic Configuration
from scm.config.security import DNSSecurityProfile
# Initialize clientclient = Scm(
client_id="your_client_id",
client_secret="your_client_secret",
tsg_id="your_tsg_id"
)
# Initialize DNS Security Profile objectdns_security_profiles = DNSSecurityProfile(client)
Usage Examples
Creating DNS Security Profiles
'name': 'basic-profile',
'description': 'Basic DNS security profile',
'botnet_domains': {
'dns_security_categories': [
{
'name': 'pan-dns-sec-malware',
'action': 'block',
'log_level': 'high',
'packet_capture': 'single-packet'
}
]
},
'folder': 'Texas'
}
# Create basic profilebasic_profile_obj = dns_security_profiles.create(basic_profile)
# Advanced profile with sinkhole and whitelistadvanced_profile = {
'name': 'advanced-profile',
'description': 'Advanced DNS security profile',
'botnet_domains': {
'dns_security_categories': [
{
'name': 'pan-dns-sec-malware',
'action': 'sinkhole',
'log_level': 'high'
},
{
'name': 'pan-dns-sec-phishing',
'action': 'block',
'log_level': 'critical'
}
],
'sinkhole': {
'ipv4_address': 'pan-sinkhole-default-ip',
'ipv6_address': '::1'
},
'whitelist': [
{
'name': 'trusted.example.com',
'description': 'Trusted domain'
}
]
},
'folder': 'Texas'
}
# Create advanced profileadvanced_profile_obj = dns_security_profiles.create(advanced_profile)
Retrieving DNS Security Profiles
print(f"Found profile: {profile.name}")
# Get by IDprofile_by_id = dns_security_profiles.get(profile.id)
print(f"Retrieved profile: {profile_by_id.name}")
print(f"Categories: {profile_by_id.botnet_domains.dns_security_categories}")
Updating DNS Security Profiles
# Update description and categoriesexisting_profile.description = "Updated DNS security profile"
existing_profile.botnet_domains.dns_security_categories.append({
'name': 'pan-dns-sec-grayware',
'action': 'block',
'log_level': 'high'
})
# Perform updateupdated_profile = dns_security_profiles.update(existing_profile)
Listing DNS Security Profiles
folder='Texas',
dns_security_categories=['pan-dns-sec-malware']
)
# Process resultsfor profile in filtered_profiles:
print(f"Name: {profile.name}")
if profile.botnet_domains and profile.botnet_domains.dns_security_categories:
for category in profile.botnet_domains.dns_security_categories:
print(f"Category: {category.name}, Action: {category.action}")
# Define filter parameters as dictionarylist_params = {
"folder": "Texas",
"dns_security_categories": ["pan-dns-sec-phishing", "pan-dns-sec-malware"]
}
# List with filters as kwargsfiltered_profiles = dns_security_profiles.list(**list_params)
Filtering Responses
The list()
method supports additional parameters to refine your query results even further. Alongside basic filters
(like types
, values
, and tags
), you can leverage the exact_match
, exclude_folders
, exclude_snippets
, and
exclude_devices
parameters to control which objects are included or excluded after the initial API response is fetched.
Parameters:
exact_match (bool)
: WhenTrue
, only objects defined exactly in the specified container (folder
,snippet
, ordevice
) are returned. Inherited or propagated objects are filtered out.exclude_folders (List[str])
: Provide a list of folder names that you do not want included in the results.exclude_snippets (List[str])
: Provide a list of snippet values to exclude from the results.exclude_devices (List[str])
: Provide a list of device values to exclude from the results.
Examples:
folder='Texas',
exact_match=True
)
for app in exact_dns_security_profiles:
print(f"Exact match: {app.name} in {app.folder}")
# Exclude all dns_security_profiles from the 'All' folderno_all_dns_security_profiles = dns_security_profiles.list(
folder='Texas',
exclude_folders=['All']
)
for app in no_all_dns_security_profiles:
assert app.folder != 'All'
print(f"Filtered out 'All': {app.name}")
# Exclude dns_security_profiles that come from 'default' snippetno_default_snippet = dns_security_profiles.list(
folder='Texas',
exclude_snippets=['default']
)
for app in no_default_snippet:
assert app.snippet != 'default'
print(f"Filtered out 'default' snippet: {app.name}")
# Exclude dns_security_profiles associated with 'DeviceA'no_deviceA = dns_security_profiles.list(
folder='Texas',
exclude_devices=['DeviceA']
)
for app in no_deviceA:
assert app.device != 'DeviceA'
print(f"Filtered out 'DeviceA': {app.name}")
# Combine exact_match with multiple exclusionscombined_filters = dns_security_profiles.list(
folder='Texas',
exact_match=True,
exclude_folders=['All'],
exclude_snippets=['default'],
exclude_devices=['DeviceA']
)
for app in combined_filters:
print(f"Combined filters result: {app.name} in {app.folder}")
Controlling Pagination with max_limit
The SDK supports pagination through the max_limit
parameter, which defines how many objects are retrieved per API call. By default, max_limit
is set to 2500. The API itself imposes a maximum allowed value of 5000. If you set max_limit
higher than 5000, it will be capped to the API's maximum. The list()
method will continue to iterate through all objects until all results have been retrieved. Adjusting max_limit
can help manage retrieval performance and memory usage when working with large datasets.
# Now when we call list(), it will use the specified max_limit for each request# while auto-paginating through all available objects.all_profiles = profile_client.list(folder='Texas')
# 'all_profiles' contains all objects from 'Texas', fetched in chunks of up to 4321 at a time.
Deleting DNS Security Profiles
dns_security_profiles.delete(profile_id)
Managing Configuration Changes
Performing Commits
"folders": ["Texas"],
"description": "Updated DNS security profiles",
"sync": True,
"timeout": 300 # 5 minute timeout
}
# Commit the changesresult = dns_security_profiles.commit(**commit_params)
print(f"Commit job ID: {result.job_id}")
Monitoring Jobs
print(f"Job status: {job_status.data[0].status_str}")
# List recent jobsrecent_jobs = dns_security_profiles.list_jobs(limit=10)
for job in recent_jobs.data:
print(f"Job {job.id}: {job.type_str} - {job.status_str}")
Error Handling
InvalidObjectError,
MissingQueryParameterError,
NameNotUniqueError,
ObjectNotPresentError,
ReferenceNotZeroError
)
try:
# Create profile configuration
profile_config = {
"name": "test-profile",
"description": "Test DNS security profile",
"botnet_domains": {
"dns_security_categories": [
{
"name": "pan-dns-sec-malware",
"action": "block",
"log_level": "high"
}
]
},
"folder": "Texas"
}
# Create the profile
new_profile = dns_security_profiles.create(profile_config)
# Commit changes
result = dns_security_profiles.commit(
folders=["Texas"],
description="Added test profile",
sync=True
)
# Check job status
status = dns_security_profiles.get_job_status(result.job_id)
except InvalidObjectError as e:
print(f"Invalid profile data: {e.message}")
except NameNotUniqueError as e:
print(f"Profile name already exists: {e.message}")
except ObjectNotPresentError as e:
print(f"Profile not found: {e.message}")
except ReferenceNotZeroError as e:
print(f"Profile still in use: {e.message}")
except MissingQueryParameterError as e:
print(f"Missing parameter: {e.message}")
Best Practices
-
Profile Configuration
- Use descriptive profile names
- Configure appropriate actions per category
- Document security decisions
- Maintain whitelist entries
- Review sinkhole settings
-
Container Management
- Always specify exactly one container
- Use consistent container names
- Validate container existence
- Group related profiles
-
Security Categories
- Configure all relevant categories
- Set appropriate log levels
- Enable packet capture selectively
- Review category actions regularly
- Document exceptions
-
Performance
- Use appropriate pagination
- Cache frequently accessed profiles
- Implement proper retry logic
- Monitor commit operations
-
Error Handling
- Validate input data
- Handle specific exceptions
- Log error details
- Monitor job status
- Track completion status
Full Script Examples
Refer to the dns_security_profile.py example.