adachsoft / workflow-step-dns
Provider-independent DNS workflow steps with pluggable DNS zone providers.
Requires
- php: ^8.3
- adachsoft/dns-zone-contracts: ^0.1
- adachsoft/dns-zone-ovh: ^0.1
- adachsoft/workflow: ^7.5
- mikepultz/netdns2: ^2.0
- psr/clock: ^1.0
Requires (Dev)
- adachsoft/php-code-style: ^0.7.4
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^13.4
- rector/rector: ^2.9
- symplify/phpstan-rules: ^14.19
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Provider-independent DNS workflow steps for adachsoft/workflow. Zone operations use only adachsoft/dns-zone-contracts, so applications can choose a DNS provider through workflow input and replace provider adapters without changing workflows.
The package includes an OVH DNS-zone provider through adachsoft/dns-zone-ovh. Applications can also register their own DnsZoneProviderInterface implementations.
Requirements and installation
- PHP 8.3 or later
adachsoft/workflow^7.5adachsoft/dns-zone-contracts^0.1adachsoft/dns-zone-ovh^0.1psr/clock^1.0
composer require adachsoft/workflow-step-dns
Register providers and steps
Use DnsZoneFactory::withDefaultProviders() to register the built-in OVH provider. Pass any application-owned providers as additional arguments; the provider selected in each step's dns input must match one of their name() values.
use AdachSoft\Workflow\Builder\WorkflowRunnerBuilder;
use AdachSoft\Workflow\Registry\InMemoryStepRegistry;
use AdachSoft\WorkflowStepDns\Steps\DnsDeleteRecordsStep;
use AdachSoft\WorkflowStepDns\Steps\DnsEnsureRecordsStep;
use AdachSoft\WorkflowStepDns\Steps\DnsListRecordsStep;
use AdachSoft\WorkflowStepDns\Steps\DnsWaitForPropagationStep;
use AdachSoft\WorkflowStepDns\Zone\DnsZoneFactory;
$dnsZoneFactory = DnsZoneFactory::withDefaultProviders(
new ApplicationDnsZoneProvider(), // Application-owned adapter implementing DnsZoneProviderInterface.
);
$stepRegistry = new InMemoryStepRegistry();
$stepRegistry->registerInstance(DnsEnsureRecordsStep::class, new DnsEnsureRecordsStep($dnsZoneFactory));
$stepRegistry->registerInstance(DnsListRecordsStep::class, new DnsListRecordsStep($dnsZoneFactory));
$stepRegistry->registerInstance(DnsDeleteRecordsStep::class, new DnsDeleteRecordsStep($dnsZoneFactory));
$stepRegistry->register(DnsWaitForPropagationStep::class);
$workflowRunner = WorkflowRunnerBuilder::create()
->withStepRegistry($stepRegistry)
->withSecretResolver($secretResolver)
->build();
ApplicationDnsZoneProvider is an application adapter, not a class supplied by this package. Implement DnsZoneProviderInterface::name() and create(DnsZoneSettings): DnsZoneInterface; use the settings' typed accessors to validate provider options. Provider exceptions should not include credentials or other secret values.
The dns step input is an object containing provider and provider-specific options. Workflow JSON represents that object as an associative array:
[
'provider' => 'custom',
'api_token' => '${secret:DNS_API_TOKEN}',
]
Configure the workflow engine's SecretResolverInterface on the runner. The engine resolves ${secret:NAME} references in mapped step input before execution; this package never resolves secret references itself. Errors returned through on_error redact resolved string values found in the step input or configuration.
The factory rejects duplicate or invalid provider names. An unknown provider error lists registered provider names in sorted order.
OVH provider
The ovh provider adapts adachsoft/dns-zone-ovh to DNS workflow steps. It accepts exactly one credential form: an env_file path or inline credentials. Do not combine them. The environment file must define OVH_ENDPOINT, OVH_APPLICATION_KEY, OVH_APPLICATION_SECRET, and OVH_CONSUMER_KEY:
$dns = [
'provider' => 'ovh',
'env_file' => '/secure/path/ovh.env',
];
Example contents for /secure/path/ovh.env:
OVH_ENDPOINT=ovh-eu
OVH_APPLICATION_KEY=your-application-key
OVH_APPLICATION_SECRET=your-application-secret
OVH_CONSUMER_KEY=your-consumer-key
Alternatively, provide all three credential keys inline. endpoint is optional and defaults to ovh-eu. Use the workflow secret resolver for the application secret:
$dns = [
'provider' => 'ovh',
'endpoint' => 'ovh-eu',
'application_key' => 'your-application-key',
'application_secret' => '${secret:OVH_APPLICATION_SECRET}',
'consumer_key' => 'your-consumer-key',
];
Create the OVH API key with these rights:
| Method | Path |
|---|---|
| GET | /domain/zone |
| GET | /domain/zone/* |
| POST | /domain/zone/* |
| PUT | /domain/zone/* |
| DELETE | /domain/zone/* |
The workflow engine resolves ${secret:OVH_APPLICATION_SECRET} before the step runs when its SecretResolverInterface is configured. Provider validation errors do not include credential values.
Steps
Every step receives input through input_map and routing targets through its config. Each step has an on_error branch with a sanitized error string.
dns_ensure_records
| Input | Type | Required | Description |
|---|---|---|---|
dns | object | Yes | Provider name and provider-specific options. |
zone | string | Yes | DNS zone name, such as example.com. |
records | list | Yes | Desired records: {name, type, value, ttl?, priority?}. |
mode | string | No | add_missing (default) or replace. |
dry_run | boolean | No | Return planned changes without writing or publishing them. |
name is relative to the zone; "" and "@" denote its apex. Supported record types are those in DnsRecordTypeEnum. priority is supported only for MX and SRV records.
| Branch | When selected | Output |
|---|---|---|
on_next | The operation completed and changes were made, or no optional unchanged target was configured. | created, updated, deleted lists and changed boolean. |
on_unchanged | No changes were needed and config.on_unchanged is configured. | The same output shape as on_next. |
on_error | Input validation or the provider operation failed. | Sanitized error string. |
Each output record is a plain array with id, name, fqdn, type, value, ttl, and priority. id, ttl, and priority may be null; name is normalized, so the apex is returned as an empty string.
add_missing leaves existing records untouched. replace reconciles every name/type pair in the desired set and may update or delete existing values for those pairs, including TXT records. Include all same-name/type values that must remain, or choose add_missing when unrelated values must be preserved. A dry run reports planned records and sets changed according to whether the plan contains operations.
dns_list_records
| Input | Type | Required | Description |
|---|---|---|---|
dns | object | Yes | Provider name and provider-specific options. |
zone | string | Yes | DNS zone name. |
name | string | No | Relative name filter; "" or "@" selects the apex. |
type | string | No | DNS record type filter. |
on_next returns records, a list of plain record arrays with id, name, fqdn, type, value, ttl, and priority. Omitting both filters lists all records in the zone.
dns_delete_records
| Input | Type | Required | Description |
|---|---|---|---|
dns | object | Yes | Provider name and provider-specific options. |
zone | string | Yes | DNS zone name. |
records | list | Yes | Selectors: {name, type, value?}. |
Each selector requires a relative name and type. Omitting value deletes all matching records for that name/type; providing it restricts deletion to matching record data. The step calls applyChanges() once when at least one record is deleted. on_next returns deleted plain record arrays and a changed boolean.
dns_wait_for_propagation
| Input | Type | Required | Description |
|---|---|---|---|
fqdn | string | Yes | Fully qualified DNS name to query. |
type | string | Yes | TXT, CNAME, or MX. |
expected_value | string | Yes | TXT substring, or CNAME/MX hostname. |
timeout_seconds | integer | No | Defaults to 300; allowed range is 0–1800. |
poll_interval_seconds | integer | No | Defaults to 15; must be positive. |
resolver | string | No | Nameserver IP address or host name; omitted uses the system resolver. |
The step uses an injectable DnsResolverInterface, PSR ClockInterface, and SleeperInterface. The default resolver uses PHP dns_get_record() with the system resolver when resolver is omitted; when supplied, the nameserver is queried with mikepultz/netdns2. The resolver input accepts a nameserver IP address or host name; host names are resolved to an IPv4 address with gethostbyname(). For fastest verification, use the zone's authoritative nameserver (for OVH zones, for example, dns106.ovh.net). Tests can inject fakes and never perform network lookups.
on_next is selected when the expected value is observed; on_timeout is selected when the timeout expires. Both return propagated and observed_values (the values from the successful or final poll respectively). TXT matching is a substring search. CNAME and MX matching is case-insensitive and ignores one trailing dot.
Example: mail DNS and propagation checks
This workflow fragment adds MX, SPF, DKIM CNAME, and DMARC records for example.com, then checks propagation. Replace the example targets and policy with values supplied by the mail provider. The custom provider name must be registered by the application.
use AdachSoft\Workflow\Engine\PayloadVo;
$steps = [
'ensure_mail_dns' => new PayloadVo([
'type' => 'dns_ensure_records',
'config' => new PayloadVo([
'on_next' => 'wait_for_mx',
'on_unchanged' => 'wait_for_mx',
'on_error' => 'dns_error',
]),
'input_map' => new PayloadVo([
'dns' => [
'provider' => 'custom',
'api_token' => '${secret:DNS_API_TOKEN}',
],
'zone' => 'example.com',
'mode' => 'add_missing',
'records' => [
['name' => '', 'type' => 'MX', 'value' => 'mx1.mail.example.net', 'ttl' => 3600, 'priority' => 10],
['name' => '', 'type' => 'MX', 'value' => 'mx2.mail.example.net', 'ttl' => 3600, 'priority' => 20],
['name' => '', 'type' => 'TXT', 'value' => 'v=spf1 include:spf.mail.example.net ~all', 'ttl' => 3600],
['name' => 'selector1._domainkey', 'type' => 'CNAME', 'value' => 'selector1.dkim.mail.example.net', 'ttl' => 3600],
['name' => 'selector2._domainkey', 'type' => 'CNAME', 'value' => 'selector2.dkim.mail.example.net', 'ttl' => 3600],
['name' => '_dmarc', 'type' => 'TXT', 'value' => 'v=DMARC1; p=quarantine; rua=mailto:dmarc@example.com', 'ttl' => 3600],
],
]),
]),
'wait_for_mx' => new PayloadVo([
'type' => 'dns_wait_for_propagation',
'config' => new PayloadVo([
'on_next' => 'wait_for_spf',
'on_timeout' => 'dns_timeout',
'on_error' => 'dns_error',
]),
'input_map' => new PayloadVo([
'fqdn' => 'example.com',
'type' => 'MX',
'expected_value' => 'mx1.mail.example.net',
'timeout_seconds' => 300,
]),
]),
'wait_for_spf' => new PayloadVo([
'type' => 'dns_wait_for_propagation',
'config' => new PayloadVo([
'on_next' => 'wait_for_dkim',
'on_timeout' => 'dns_timeout',
'on_error' => 'dns_error',
]),
'input_map' => new PayloadVo([
'fqdn' => 'example.com',
'type' => 'TXT',
'expected_value' => 'v=spf1 include:spf.mail.example.net ~all',
]),
]),
'wait_for_dkim' => new PayloadVo([
'type' => 'dns_wait_for_propagation',
'config' => new PayloadVo([
'on_next' => 'wait_for_dmarc',
'on_timeout' => 'dns_timeout',
'on_error' => 'dns_error',
]),
'input_map' => new PayloadVo([
'fqdn' => 'selector1._domainkey.example.com',
'type' => 'CNAME',
'expected_value' => 'selector1.dkim.mail.example.net',
]),
]),
'wait_for_dmarc' => new PayloadVo([
'type' => 'dns_wait_for_propagation',
'config' => new PayloadVo([
'on_next' => 'mail_dns_ready',
'on_timeout' => 'dns_timeout',
'on_error' => 'dns_error',
]),
'input_map' => new PayloadVo([
'fqdn' => '_dmarc.example.com',
'type' => 'TXT',
'expected_value' => 'v=DMARC1; p=quarantine',
]),
]),
// Define application-specific terminal/error steps for mail_dns_ready, dns_timeout, and dns_error.
];
add_missing is used here to preserve unrelated existing TXT records. If using replace, provide the complete desired TXT set for each affected name/type pair.
Example: Pinterest or Google domain verification
Add the verification token as a TXT record, then wait for the value to appear. Use name => '' when the service instructs you to publish the token at the zone apex; otherwise use the instructed relative name.
$verificationInput = [
'dns' => [
'provider' => 'custom',
'api_token' => '${secret:DNS_API_TOKEN}',
],
'zone' => 'example.com',
'mode' => 'add_missing',
'records' => [
['name' => '', 'type' => 'TXT', 'value' => 'google-site-verification=REPLACE_WITH_GOOGLE_TOKEN'],
// Or: ['name' => '', 'type' => 'TXT', 'value' => 'pinterest-site-verification=REPLACE_WITH_PINTEREST_TOKEN'],
],
];
$verificationWaitInput = [
'fqdn' => 'example.com',
'type' => 'TXT',
'expected_value' => 'google-site-verification=REPLACE_WITH_GOOGLE_TOKEN',
'timeout_seconds' => 600,
'poll_interval_seconds' => 15,
// Optional: 'resolver' => '1.1.1.1',
];
Map $verificationInput to dns_ensure_records and $verificationWaitInput to a following dns_wait_for_propagation step. Route on_timeout to retry or report that DNS is not yet visible.
Custom providers
A provider adapts its service API to the provider-independent DnsZoneInterface from adachsoft/dns-zone-contracts:
use AdachSoft\DnsZoneContracts\Service\DnsZoneInterface;
use AdachSoft\WorkflowStepDns\Zone\DnsZoneProviderInterface;
use AdachSoft\WorkflowStepDns\Zone\DnsZoneSettings;
final readonly class ApplicationDnsZoneProvider implements DnsZoneProviderInterface
{
public function name(): string
{
return 'custom';
}
public function create(DnsZoneSettings $settings): DnsZoneInterface
{
return new ApplicationDnsZoneAdapter(
apiToken: $settings->requireString('api_token'),
);
}
}
ApplicationDnsZoneAdapter is application-owned and must implement DnsZoneInterface. Use DnsZoneFactory to register multiple providers and select them by the dns.provider input. Provider-specific configuration stays outside workflow-step logic.