Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(aws): add support to route53 simple records #715

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

marcelohpf
Copy link

@marcelohpf marcelohpf commented May 9, 2024

Changes

This includes the support to Simple Route policy from Route53.

Details:

  • Set default TTL to 300s as it is same default interval as ddns-updater
  • It implements only Simple Routing, there are other 7 policies available for route53, but it is not a use case for me. If there are larger interest on them, I can send more PRs.
  • Providing the basic policy from documentation is enough for upserting domains following least privilege accesses
  • Uses only Static Credentials following this project design (/data/config.json for all provider configs).
  • It doesn't wait for propagation (GetChange API) because it updates one domain at a time and runs quite often.

Testing

Build container and ran with the default configs and using policy in the documentation

Here is one event for a domain that didn't exit at route53

{
    "eventVersion": "1.09",
    "userIdentity": {...},
    "eventTime": "2024-05-09T18:10:47Z",
    "eventSource": "route53.amazonaws.com",
    "eventName": "ChangeResourceRecordSets",
    "awsRegion": "us-east-1",
    "sourceIPAddress": "<redacted>",
    "userAgent": "DDNS-Updater quentin.mcgaw@gmail.com",
    "requestParameters": {
        "hostedZoneId": "<redacted>",
        "changeBatch": {
            "comment": "Record updated by ddns-updater",
            "changes": [
                {
                    "action": "UPSERT",
                    "resourceRecordSet": {
                        "name": "test.<my-domain>",
                        "type": "A",
                        "tTL": 300,
                        "resourceRecords": [
                            {
                                "value": "<redacted>"
                            }
                        ]
                    }
                }
            ]
        }
    },
    "responseElements": {
        "changeInfo": {
            "id": "/change/<redacted>",
            "status": "PENDING",
            "submittedAt": "May 9, 2024 6:10:47 PM",
            "comment": "Record updated by ddns-updater"
        }
    },
   ...
}

Note: this is a partial implementation of #375 because AWS route53 supports many more DNS features.

Copy link
Owner

@qdm12 qdm12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! It looks quite good, I just wonder if it could be achieved without using their Go SDK to rely on less dependencies (call me crazy, that's fair enough as well!)

@@ -20,13 +20,15 @@ var (
ErrHostNotSet = errors.New("host is not set")
ErrHostOnlySubdomain = errors.New("host can only be a subdomain")
ErrHostWildcard = errors.New(`host cannot be a "*"`)
ErrHostedZoneIDNotSet = errors.New("hosted zone id is not set")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use ErrZoneIdentifierNotSet instead? 🤔

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated as requested. Please, take a look

ErrIPv4KeyNotSet = errors.New("IPv4 key is not set")
ErrIPv6KeyNotSet = errors.New("IPv6 key is not set")
ErrKeyNotSet = errors.New("key is not set")
ErrKeyNotValid = errors.New("key is not valid")
ErrNameNotSet = errors.New("name is not set")
ErrPasswordNotSet = errors.New("password is not set")
ErrPasswordNotValid = errors.New("password is not valid")
ErrSecretAccessKeyNotSet = errors.New("secret access key is not set")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would ErrSecretNotSet or ErrKeyNotSet fit?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use existing errors, please take another look.

if err != nil {
return nil, fmt.Errorf("validating provider specific settings: %w", err)
}
ttl := int64(300)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super-nit tll for DNS are int32 as far as I know 😉

Comment on lines 53 to 56
region := "us-east-1"
if providerSpecificSettings.Region != "" {
region = providerSpecificSettings.Region
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we enforce the region to be set perhaps? What's the reason to default to us-east-1?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No specific reason for that. I just got watherver region UI was showing at the moment for the 'Global Access', I will make it mandatory.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found out that signing requests for Global Resources must be with Region us-east-1. As the goal is to UPSERT, the ddns-updater should make requests only to us-east-1. I will remove the Region from options.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the region to be us-east-1 due to the limitations. Please, take another look

internal/provider/providers/aws/provider.go Outdated Show resolved Hide resolved
docs/aws.md Outdated Show resolved Hide resolved
docs/aws.md Outdated Show resolved Hide resolved
docs/aws.md Outdated Show resolved Hide resolved
docs/aws.md Outdated
- `"host"` is your host and can be a subdomain or `"@"` or the wildcard `"*"`
- `"aws_access_key_id"`
- `"aws_secret_access_key"`
- `"hosted_zone_id"`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be replaced with zone_id perhaps? 🤔

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried using AWS specific names, I can replace this by zone_id and update the doc to reference the HostedZone ID

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to zone_id. Please, take another look.

docs/aws.md Outdated Show resolved Hide resolved
Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>
* Implements the request signing version 4
* Print formatted error messages
* Remove optional region to global resource
* Rename config settings
@marcelohpf marcelohpf force-pushed the feat/aws-simple-record branch 2 times, most recently from 3c0cf50 to 03ee321 Compare May 19, 2024 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants