Tuesday, 18 February 2020

AWS - Cross Account access using #IAM

Access multiple AWS accounts

Amazon says that you should have an account for different services, projects and clients.
This can get confusing very quickly, as you may end up with many many user ids and passwords.

There are many tutorials and follow-me videos on this topic but they can very confusing.
Personally I have found these two useful:

How to do it?

Let's assume you have two accounts ROOT and CLIENT. (Most examples have dev and prod and the like, but that does not give the relationship).
The ROOT account is where you control all the users and the account that is your main account. The account that pays for everything.
The CLIENT project could be where you host some lambdas for a specific client. An account you want to keep separate.

Step #1 - Root account number

Take note of your ROOT account number.
This can be found at the top of this page in the console: https://console.aws.amazon.com/billing/home?#/account

Do the same for your other account.

Step #2 - Set up cross-account access in the ROOT

Log into your ROOT account.
In IAMS create a policy called CrossAccountAssumeRole.
All this role needs to do is allow all actions on STS and for all resources.
Create a group called CrossAccount with this role attached to it.
Place the users who you wish to be allowed cross-account access the new group.

Step #3 - Allow your other account to connect to the ROOT

Log in to your other account CLIENT.
Create a new policy for your cross-account user to be assigned when it assumes its role.
This is important as this is the role that will define what your other account is allowed to do.
It will not be a Group or User ... its a role!
A useful AWS defined policy for cross-account admin is ... AdminsitratorAccess ... so we will use this.

Click create Role;
Select the trusted entity as "Another AWS account";
This will ask you for an account id. This is the id of the ROOT account (step #1).
This is important as it is to establish trust between the CLIENT and the ROOT. 
And no I don't know why sub-accounts don't trust the ROOT account implicitly.
There are two checkboxes on that screen for MFA and external ID ... either ignore them or add MFA.
Attach as many or as few policies as you need the role to have.
You will be asked what the users who can have this are ... ignore this for now.
Call the role "MainAccountAdminRole".

You can create many roles this way and as you might create User groups the Roles can be for any purposes.

Step #4 - Assume the Position role

Now log out and back into the ROOT account;
On the menu bar under your login name will be the option "Switch Role";

You will be presented with a screen asking for Account.
This is the account CLIENT Id from step #1, ... type it in.
You are asked for the role ... this is the role you just created in step #3, .. "MainAccountAdminRole".
Add a nice display name ... "Client" and a colour.

Then click switch role.

And you are in!

Beware!

There are some bear traps along the way here so be mindful:
- The role in the CLIENT account can do anything it is assigned to do. So admin access could be dangerous
- The "Switch role" settings exist in your browser cache. So you will need to set up the switch roles for new browsers, etc.


-- Enjoy!





Tuesday, 18 December 2018

Fixing your BASH colours

The default colours on Windows Linux Subsystem are terrible.
But the issue is a BASH problem and not a WLS issue.

To fix it to something nicer...
By default, the colours in windows 10 BASH shell are so terrible it's pretty hard to read the folder names. To fix this append the following two lines to your $HOME/.bashrc file.

LS_COLORS='rs=0:di=1;35:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=01;36;40:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:';
export LS_COLORS
If these changes are not to your liking check out these links:



Monday, 17 December 2018

Gerkin, Cucumber & BDD

http://guide.agilealliance.org/guide/gwt.html

Given - When - Then

Definition

The Given-When-Then formula is a template intended to guide the writing of acceptance tests for a User Story:
  • (Given) some context
  • (When) some action is carried out
  • (Then) a particular set of observable consequences should obtain
An example:
  • Given my bank account is in credit, and I made no withdrawals recently,
  • When I attempt to withdraw an amount less than my card's limit,
  • Then the withdrawal should complete without errors or warnings

https://github.com/cucumber/cucumber-js
http://stackoverflow.com/questions/14638254/gherkin-to-not-for-javascript
http://blog.josephwilk.net/ruby/testing-javascript-with-cucumber-in-javascript.html
http://cucumber.github.io/cucumber-eclipse/
https://thomassundberg.wordpress.com/2014/05/29/cucumber-jvm-hello-world/
http://behat.readthedocs.org/en/v2.5/guides/1.gherkin.html
http://custardbelly.com/blog/blog-posts/2014/01/08/bdd-in-js-cucumberjs/
https://cukes.info/

The mystery of OAuth

The puzzle

Probably like many people I am perplexed by OAuth2.
No sooner do I think that I have worked out what it is I find that the next time I look it has changed or someone is describing it differently.

So this page is me pulling a few notes & sites together for reference.
If they help you then all to the best.

References



  1. A good place to start is this talk on the topic:

    This guy manages to simplify the whole mystery.
    He also references two nice resources.
    • OAuth 2.0 <debugger/> ... https://oauthdebugger.com/
    • And a grant debugger (link todo)
  2. A PHP libary but the documentation is surprisingly clear and easy to read.
    http://oauth2.thephpleague.com/
    The flow chart to select the grant type is especially good:

    The above can be found on http://oauth2.thephpleague.com/authorization-server/which-grant/
  3. A second nice reference is the microsoft site: https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-v2-protocols
    This too has some useful & simple diagrams.
    Such as this one:

    Which shows a simplified relationship between servers.

Thursday, 18 October 2018

Cloud Usage Guidance



Cloud environments are great - they enable us to do things faster, experiment, work collaboratively, etc, etc. However, without care, cloud environments can also become security risks and burn through cash quickly.


Two of the most important principals are:
Security: Apply a least-privilege approach to cloud resources, i.e. only allow access to the people that need it. This means consideration of ports, IP addresses and user permissions that need to be granted access
Cost: Understand the cost of resources that you're creating and ensure they are destroyed when they're no longer required and, ideally, turned off or scaled-down (vertically and horizontally) when not in use

The following sections provide some guidance to consider when creating and using cloud resources. The principals behind the recommendations are agnostic of the cloud provider, albeit the implementation might differ slightly for each and examples given are more focused on AWS.
The intention is for everyone to be aware of the various considerations that apply to the use of cloud environments, even if you're just spinning up a single VM to learn about the cloud.

Security

We are not re-inventing the wheel, as there are many existing security practices for AWS and Azure, e.g. for AWS, it's worth checking these out:
https://d0.awsstatic.com/whitepapers/aws-security-best-practices.pdf
http://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html

Network Security Considerations

It is critical that network security controls, especially Security Groups (in AWS) and Network Security Groups (in Azure), are implemented correctly and consistently to avoid creating holes, or vulnerabilities, in the security posture of your environments. This will also ensure that in the nightmare scenario of a security breach of a VM, the damage can be as limited as possible.

A few considerations, which mostly relate to IaaS, but should be considered for all environments are:
  • Traffic should only be permitted to travel within and between networks on a least-privilege basis, particularly for those environments that contain client data or are connected to a client  network, only granting access to those security groups, IPs and protocols that are known, understood and trusted
  • There should never be any Security Groups created with the default 0.0.0.0/0 for ALL protocols for outbound traffic. This applies to public and private subnets. For example, if a VM was hacked, it would be harder (i.e. slow them down, if not stop them) for the attacker to jump from that VM to another or use it for other nefarious activities, if non-essential outbound ports are not permitted - considering that SG rules are stateful, it's unlikely that you'll need outbound SSH (port 22) permitted on any server other than a jump/bastion server.
  • Routing tables should ensure that traffic is only routed between subnets and VPCs that require it. Where possible, Security Groups should reference other Security Groups, rather than IP addresses directly when setting rules for the same or peered VPCs
  • Inbound security group rules should IP whitelist all traffic unless there is a very strong reason not to,
    AND a comment should be added to describe exactly what that IP refers to. Usually, all traffic originating from a Client's office network or the client VPN will have the same IP address, so this should be used on all externally accessible ports/endpoints.
  • In a more mature environment, it is preferable for security group rules to be scripted and regularly reapplied/enforced via automation to force people to formalise and document network access in scripts any avoid manually added rules that could adversely affect the security posture of the environment.
  • When designing environments, or even doing PoCs with any kind of sensitive data or other information, use subnets to segregate public and private networks and consider how the servers and services are accessed, e.g. via jump/bastion servers, rather than directly connecting all servers to the internet (in an ideal world, automation of deployment, configuration, log access, etc would eliminate virtually all need for a user to log on to a server)

IAM Best Practices

VPC Best Practices

  • Always assign security groups to instances
  • Consider using existing security groups before creating new ones, however, only re-use SGs across similar instances/services to avoid confusion and inadvertently adversely affecting the security of another instance by changing a shared SG
  • For Security Groups, open only ports you really need to be opened and restrict access to these ports
  • Avoid exposing instances to the Internet whenever possible
  • Consider enabling Flow Logs (http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/flow-logs.html)
  • Restrict egress traffic, avoid allowing outbound connections for any port to anywhere

EC2 Best Practices

  • For opening access to the instance from the Internet use Elastic Load Balancer
  • Always use HTTPS for publicly exposed HTTP-type services
  • Enable access logs collection for your ELBs (https://aws.amazon.com/blogs/aws/access-logs-for-elastic-load-balancers/)
  • For inter-service communication always route traffic only via a private network (meaning either instanceA→internal ELB→ instanceB or instanceA→InstanceB, but no instanceA→Public ELB→InstanceB)
  • Use bastion servers to access instances via SSH/RDP

S3 Best Practices

Cost

  • Some cloud services are effectively free with low usages, such as AWS Lambdas and Azure Functions, but others aren't. Therefore, please be mindful of the cost of the resources being created. The considerations should include:
  • The size of the resource (e.g. for a VM, it's the number of CPUs and size of RAM; for disks, it's the type/speed and capacity)
  • Whether the resource is charged all the time (see below)
  • Whether the resource can be scaled down / turned off, when not in use
  • Whether there are more cost-effective ways of achieving the same thing
This does not mean don't try or use certain services, it just means be mindful of the consequences.

AWS and Azure provide comprehensive pricing pages and calculators to help with this.
For example, for VMs: As mentioned above, the pricing models for cloud resources vary, here are a few different types:
  • Charged whilst running - VMs are a good example of this (but their storage is usually billable even when the VM is shut down)
  • Charged when used - Lambdas / Functions are a good example
  • Charged until destroyed - RDS is a good example
It is also worth checking whether there are any free credits that are available.

Friday, 14 September 2018

Thought of the day: Questions to ask your clients and developers?

There are times when it is a great idea to ask your clients and your developers a few questions about the project you are about to join.

Naturally, you will not be able to ask all the people the questions but you never know.
However, the answers should give you a rough idea of the maturity of the project.

The following table is an overview of the detail & questions you may need from each of the stakeholders. You may determine that additional/different people are needed to fulfil this and some people may have multiple roles but it should be a starting point.


Who (Client)
Information sought
Project Sponsor
  1. Provide an overview of the Objectives and benefits expected
  2. What are the Business’ general expectations of the project? How are they being assessed?
  3. What are the Business’ technical expectations of the project? How are they being assessed?
  4. What are the Business’ security expectations of the project? How are they being assessed?
  5. Is there a feature project roadmap and is it shared with the Team?
Product Owner

  1. Provide an overview of the prioritised delivery roadmap
  2. What are the Business’ general expectations of the project?
  3. What are the Business’ technical expectations of the project?
  4. What are the Business’ security expectations of the project?
  5. Is there a feature project roadmap and is it shared with the Team?
  6. What security requirements has the business placed on the system?
  7. What non-functional and performance requirements has the business placed on the system?
  8. What is the current and future growth of the system expected to be?
  9. Are requirements prioritised using a MoSCoW scheme?
  10. As PO are you involved in the Sprint planning phases of the project?
  11. Are you involved in the development of the project feature backlog?
  12. Are you involved in the development of the sprint planning process?
  13. Are technical blockers reported to you?
  14. Is there sufficient project information being provided by the team to assist with the creation of further requirements?
  15. Provide a walkthrough of the feature backlog and priority
  16. Provide insight into the current issue/risks/constraints to the project
Project Manager
  1. Provide an overview of the current SDLC, measures and controls
  2. What are the processes & tools for requirements control?
  3. Does the project have a Release timeline?
  4. What is the process the team is following to control their development? If it is agile can you describe the process?
  5. Who is involved in the development of the project feature backlog and whats the process?
  6. Who is involved in the development of the sprint planning process and whats the process?
  7. As PM how would you describe your role in this SDLC?
  8. Does the project have a measurable sprint velocity?
  9. As PM are you involved in the Sprint planning phases of the project?
  10. How are testing outcomes & blockers/impediments reported and tracked?
  11. Are technical blockers reported to you?
Data/Business Analyst
Business SME
  1. What is the Business’ general expectations of the project?
  2. Provide an overview of the top priority Use Cases for the solution
  3. What are the processes the system needs to perform?
  4. What is the current quantity of data the system must process?
  5. What are the data sources, transformations and outputs the system must perform? (schemas, definitions, data flows etc)
  6. What security requirements has the business placed on the system?
  7. What performance requirements has the business placed on the system?
  8. What is the current and future growth of the system expected to be?
  9. How are the requirements communicated to the team?
  10. How is system functionality measured against the requirements?
Technical Architect
  1. What is the overall System architecture context?
  2. What are the main functional components of the system?
  3. What are the processes & tools for requirements control?
  4. Are you involved in the development of the project feature backlog?
  5. Are you involved in the development of the sprint planning process?
  6. What security requirements were placed on the system?
  7. What performance requirements were placed on the system?
  8. What is the current and future growth of the system expected to be?
  9. What architecture requirements were placed on the system?
  10. What other non-functional requirements were placed on the system?
  11. Is there a Disasters recovery plan for the system? If so how is it implemented architecturally?
  12. Is it possible to get access to all existing design notes for the system?
  13. How are design choices and patterns communicated with the team for development?
  14. Is there a deployment strategy or process for the system? (Infrastructure as code?)
  15. Is there a testing/assurance strategy or process for the system?
  16. When there are issues with the development are you informed and consulted?
  17. When there are issues reported by assurance are you informed and consulted?
  18. Prior to the system going operational are you consulted by the Assurance, Operations or development team on how systems should be configured, or any potential issues?
  19. When in operation do you have visibility of operational monitoring systems?
  20. Once the system is deployed how do you know that it has been deployed according to your specification?
  21. Does the system have a ‘Technical Debt log’ or a list of known issues?
  22. Provide an overview of the solution architecture
  23. Provide details of constraints, dependencies and issues encountered and impacting delivery
Vendor Tech Lead
  1. How are requirements communicated to the team?
  2. What is the process the team is following to control their development? If it is agile can you describe the process?
  3. Are you involved in the development of the sprint planning process?
  4. Is the team aware of the release schedule for the system?
  5. Is the team recording development information in some way? If so using which tool?
  6. What security requirements were placed on the system?
  7. What performance requirements were placed on the system?
  8. What architecture requirements were placed on the system?
  9. What is the process of reporting progress in development back to project management?
  10. What are the development toolsets in use across the team?
  11. When source code is developed what coding standards are being followed?
  12. When source code is being developed which source code management (SCM) tool is in use?
  13. Who has Source code access?
  14. When a build of the system is performed what are the build artefacts and how are they stored?
  15. What is your SCM versioning & branching & merging strategy?
  16. When defects are found, how are they reported, tracked and reported?
  17. What are the capabilities of development staff & their relative strengths?
  18. Is the team following a BDD/TDD development approach?
  19. What level of code review is performed during development?
  20. What is the release process for new functionality?
  21. Do you produce release notes for each new release?
  22. How many environments are used for development?
  23. What is the process for procuring cloud development stacks?
  24. What are the data sets used during development?
  25. How is the development environment secured?
  26. Is there a build process for the system? If so what is it?
  27. Is the system deployable using automation tools? If so what are they?
  28. What level of testing (manual & automated) exists for the system to prove functional & non-functional requirements?
  29. When the system is in UAT what information/documentation is requested by Assurance to determine the available functionality?
  30. When the system is in LIVE what information/documentation is requested by Operations regarding its operation and deployment?
  31. Provide an overview of the solution and the code
  32. Provide details of constraints, dependencies and issues encountered and impacting delivery
  1. Security & Compliance

  1. Provide an overview of the prioritised Security & Compliance requirements for the solution
  2. When the system requirements are being determined was security consulted?
  3. When the system is being developed what involvement does Security have?
  4. When the system deployment is being planned is Security consulted?
  5. Is Security informed of code related security issues?
  6. Is security informed of how the system is tested for compliance with security requirements?
  7. When operational how is the security of the system managed?
  8. If there is a security issue with the system how are you informed?
  9. What is your process for reporting a security breach?
  10. Provide an overview of constraints & dependencies for delivery
Assurance Lead
  1. Provide an overview of the testing strategy and framework
  2. Provide an overview of the test coverage on the solution and the measures in place
  3. What involvement does assurance have in the code-Review process?
  4. What level of functional testing does assurance perform on the system?
  5. What level of non-functional testing does assurance perform on the system?
  6. What proportion of the testing is automated vs manual?
  7. Does the system have automated test reports and how are they reported to assurance
  8. What is the test plan for penetration testing?
  9. How does assurance get involved with the defect management process?
  10. Does assurance have any input on the architecture of the system?
  11. Once deployed what involvement does Assurance have with the system?
Operations
  1. Provide an overview of the path to live/transition to live process.
  2. When the system is being designed what visibility do you have or need of its functional requirements?
  3. When the system is being designed what visibility do you have or need of any security requirements?
  4. When infrastructure is needed by the Development, Test and support team what is the process they must follow?
  5. How are you informed by development of the build artefacts needed for deployment?
  6. How do you enable or control the provisioning of cloud resources by the development team?
  7. What information do you need regarding the security of the proposed system?
  8. What information do you need about the testing process?
  9. How are deployment details of the Deployment & Configuration process communicated to you?
  10. What is the process for post-deployment system testing?
  11. How is performance and systems failure reported?
  12. What are the Monitoring processes and how & what is reported?
  13. If the system has a bug how is it reported and who does the repair work?
  14. What are the system’s supported hours?
  15. What is the systems supported availability?
  16. What is the DR plan for the system?
  17. When in operation does development have access to the system to perform fault analysis?

 Have fun!

Tuesday, 21 August 2018

A problem with AWS: IAM Policies

Today I had an issue where I wanted to create a Power Developer user.
So I promptly went to the managed roles and used the Developer Power User and clicked apply.
It seemed ok until I attempted to look at Lambdas and I hit issue after issue with missing roles.
So I have created this policy and it seems ok so far:
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "NotAction": [
                "iam:*",
                "organizations:*"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "iam:CreateServiceLinkedRole",
                "iam:DeleteServiceLinkedRole",
                "iam:ListRoles",
                "iam:ListRolePolicies",
               "iam:GetRole",
               "iam:ListAttachedRolePolicies",
               "iam:GetPolicy",
               "iam:GetPolicyVersion",
                "organizations:DescribeOrganization"
            ],
            "Resource": "*"
        }
    ]
}

The items in bold are the additional rights the policy needed for the Lamda console to work.
Ideally, this should be 'LambdaConsoleRole' or some such but I am still learning.