Skip to content

Override Hostname for A/PTR record #5

Closed
cho00013 opened this issue Jan 31, 2022 · 8 comments
Closed

Override Hostname for A/PTR record #5

cho00013 opened this issue Jan 31, 2022 · 8 comments
Assignees

Comments

@cho00013
Copy link
Contributor

if "boc:dns:name" Tag is filled or "Name" tag is filled, use that field instead of the default ip-1-2-3-4 as the name.

@cho00013
Copy link
Contributor Author

cho00013 commented Jan 31, 2022

Per @badra001 's email.

I think that for EMR, the Name (ip-1-2-3-4) is the default and can be used. I'm mulling around the following
create A record with default_name ip-1-2-3-4 . zone (where zone is either boc:dns:zone or from dhcp)
> make it optional for everything (env variable) or per instance (boc:dns:options, TBD)
get IP
get PTR subnet for IP (ipv4: /24 block), get zone
get boc:dns:name (if exists) or Name if not
strip into host part (before dot) and domain (after dot)
> if domain exist and is associated, we can proceed
> add A record with host + validated domain
> add PTR with this same host + validated domain in proper zone
keep a list of the records written in ddb as an attribute (associated to this instance)
> resource_record = list of maps
> type (A, AAAA, PTR, CNAME, TXT, ...)
> zone name
> zone id
> name
this way, you can easily go through all that were created and remove them

@cho00013
Copy link
Contributor Author

cho00013 commented Jan 31, 2022

@badra001 - for this statement:

No, only one PTR, for the primary name:
if Name or boc:dns:name, that's the primary name for the PTR
if not, primary name for PTR is the ip-1-2-3-4

Do we want to still create 1 A record or 2? So if boc:dns:name has hostname.zone. then do we create ip-1-2-3-4.zone as well as hostname.zone? Or just hostname.zone?

@cho00013 cho00013 self-assigned this Jan 31, 2022
@cho00013
Copy link
Contributor Author

cho00013 commented Feb 4, 2022

So running through all of the permutations, the logic below is what I am going to use to update the code.

I'm writing this in python-like statement format but the syntax/logic will be little more complex 🙂

if boc:dns:name field is present AND boc:dns:zone is valid:

We strip out FQDN if present - only take the Hostname (split using "." and take the most left entry)
Can accept "shortname" like 'testhost'
use boc:dns:zone as the Zone as long as it's associated with VPC
create a and ptr record using boc:dns:name Value in the correct zone.

elif boc:dns:name field is present AND boc:dns:zone is not valid:

We strip out FQDN if present - only take the Hostname (split using "." and take the most left entry)
Can accept "shortname" like 'testhost'
use DHCP option DNS name as zone
create a and ptr record using boc:dns:name Value in the correct zone.

elif Name field is present and FQDN matches the VPC DHCP option

DHCP option matches the FQDN zone specified in Name value. So if a different zone is specified, Name tag/value is ignored.
If the Name field is NOT DNS supported, it will be ignored. So if Name field is like a random (e.g. 'my test ec2 host') it will be ignored. 
Create A/PTR record using the Name field

elif boc:dns:zone present and valid

use ip-1-2-3-4 as hostname
use boc:dns:zone as the zone  

else # this is the current

use ip-1-2-3-4 as hostname
use dhcp option DNS name for the zone 

*For CNAME (boc:dns:cname), it will create a CNAME to the field A record created above.

  • boc:dns:name can be shortname (fqdn will only ignored).
  • boc:dns:zone can be used to override the DHCP option DNS name.
  • Name must be FQDN AND match the zone must match the DHCP option DNS zone name.

It's little convoluted to try to inject the logic to the where we want but let me know if above logic makes sense. I need to probably reshuffle some of the code. I am going to remove all of the commented out code (e.g. zone creation, public dns record check, etc) to make the code easier to decode.

@badra001
Copy link
Contributor

badra001 commented Feb 4, 2022

What we need is "hostname selection code", as function, to make the code easier to handle. It ultimately spits out

  • hostname (short name)
  • zone (domain)

And then these can be added accordingly.

@cho00013
Copy link
Contributor Author

cho00013 commented Feb 4, 2022

@badra001 - I changed up the script considerably. It's not in the function format but I have streamlined the code.

https://github.e.it.census.gov/terraform-modules/aws-dynamic-route53/tree/awspeter_version007

I've updated the file the branch above. Please take a look.
https://github.e.it.census.gov/terraform-modules/aws-dynamic-route53/blob/awspeter_version007/code/ddns-lambda.py

I've put a comment at the top that explains the rough idea of what the script.

Also, I've removed all of the commented out code that weren't being used. The code is pretty much the same as before but I've moved some parts around, put things into a if/elif/else format to make the logic more readable. And 1 statement that either creates the A/PTR or delete A/PTR record. And finally, the CNAME creation is only if the CNAME tag is valid.

I've done all different permutation testing and it is working as I expected it. I can go ahead and attach the test result (from my lab).

@cho00013
Copy link
Contributor Author

Per Don's email, change the logic

if Name exist, split Name into host, domain
if boc:dns:zone present and valid
RR = host + boc:dns:zone
if not, and domain is valid
RR = host + domain
if not,
RR = host + dhcp_domain

if name not exists, use private dns host part (ip-1-2-3-4)
RR = private dns host part + dhcp_domain

@cho00013
Copy link
Contributor Author

revision made in pull request
#11

@cho00013
Copy link
Contributor Author

Closing. This is completed.

Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants