Skip to content

Commit c731d76

Browse files
author
Pål-Magnus Slåtto
committed
🚀 Initialize workshop repository
1 parent 4639967 commit c731d76

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+18870
-0
lines changed

.github/SECURITY.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Security notice
2+
This repository is intended for workshop purposes only.
3+
4+
For demonstrating some of the benefits containerised development have there will be some security vulnerabilities introduced by design in this repository.
5+
6+
Always validate that your depencencies is up to date before introducing this workflow to your development workflow.
7+
8+
Feel free to contact the project owners with any questions regarding security in this repo.

.github/workflows/stale.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: 'Close stale issues and PRs'
2+
on:
3+
schedule:
4+
- cron: '0 0 * * *'
5+
6+
jobs:
7+
stale:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/stale@v6
11+
with:
12+
repo-token: ${{ secrets.GITHUB_TOKEN }}
13+
# Staling issues and PR's
14+
days-before-stale: 30
15+
stale-issue-label: stale
16+
stale-pr-label: stale
17+
stale-issue-message: |
18+
This issue has been automatically marked as stale because it has been open 30 days
19+
with no activity. Remove stale label or comment or this issue will be closed in 10 days
20+
stale-pr-message: |
21+
This PR has been automatically marked as stale because it has been open 30 days
22+
with no activity. Remove stale label or comment or this PR will be closed in 10 days
23+
# Not stale if have this labels or part of milestone
24+
exempt-issue-labels: bug,wip,on-hold
25+
exempt-pr-labels: bug,wip,on-hold
26+
exempt-all-milestones: true
27+
# Close issue operations
28+
# Label will be automatically removed if the issues are no longer closed nor locked.
29+
days-before-close: 10
30+
delete-branch: true
31+
close-issue-message: This issue was automatically closed because of stale in 10 days
32+
close-pr-message: This PR was automatically closed because of stale in 10 days

CHANGELOG

Whitespace-only changes.

CONTRIBUTING.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Contributions to the workshop files
2+
I'm thrilled that you want to contribute to the workshop files, thanks! 🥳
3+
4+
To make it easier for you to contribute I've added some notes about what to keep in mind when contributing to this repository.
5+
6+
## Bug and Feature requests
7+
The best way to report a bug or feature request on this project is to use the issues panel in the repository. Please mark the ticket with either `[BUG]` or `[FEATURE REQUEST]` in the start of the title to make it easy for maintainers to catagorise what's submitted. It's always nice to check the existing reports to see if anyone else has the same bug or request as you. If that's the case then you should rather give that ticket a upvote and follow the ticket. This helps the maintaner prioritise the tickets, resulting in you geting your requested feature or bugfix implemented faster.
8+
9+
## Pull requests
10+
By default we squash changes on the main and completed banches to keep the Git-log clean, and then make sure that the squash commit includes the Pull request number so we can go back and see in more details.
11+
12+
Always make sure that all tests and workflows passes whenever you've med a change. The most important thing with workshop files is that they actually work as intended for the end-users. Any changes that requires the end-user of this repository to run commands or have things installed for the files to run must be updated in the README.md of the relevant project.
13+
14+
All pull requests on the application code should be opened against main, and then be rebased down to completed after merge. All changes regarding the devcontainer configs should be opened agains the completed branch.

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Example files for Development Containers
2+
**Welcome to the workshop files for working with development containers!👋🏻**
3+
4+
This repository was created for [Security Champions Norway's meetup #3](https://sikkerhet.bouvet.no/security_champion/meetup_scnorge_3/) at Bouvet, and the keynote `Cloud Development: Secure your endpoints with containerised development environments`.
5+
6+
If you find this repository valuable, feel free to give it a star ⭐️
7+
8+
This project is structured with the main branch containing four different example applications in different languages (C#, Java, Typescript & Python) exposing a web server. On the branch `complete` you will find the same files, but now with a config for running development containers for the different applications. If you want to contribute to these files or want examples for other languages, please have a look at [CONTRIBUTING.md](CONTRIBUTING.md)
9+
10+
## What is Develpoment Containers?
11+
A Development Container (or Dev Container for short) allows you to use a container as a full-featured development environment. It can be used to run an application, to separate tools, libraries, or runtimes needed for working with a codebase, and to aid in continuous integration and testing. Dev containers can be run locally or remotely, in a private or public cloud.
12+
13+
One of the big benefits with development containers is that your work environment will work the same way both on Github Codespaces, as well as locally on your machine. This makes it possible to work on the Codespaces (online) by default, but also having the workspace locally if you need to work offline.
14+
15+
For development containers to work you would need to have a `.devcontainer` folder in your repository with a `devcontainer.json` file. To see the definition of the json file, navigate to the [documentation](https://github.com/microsoft/vscode-dev-containers/tree/main/containers) for development containers.
16+
17+
## Local development with containers
18+
In this workshop we'll use Virtual Studio Code as our editor for working with the development containers. For this to work, you will have to download the VSCode [Dev Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) plugin.
19+
20+
This will help you spin up repositories with existing configs, and even better - help you configure new repositories with a step-by-step guide.
21+
22+
Note that you need to have Docker installed locally as the plugin utilises this under the hood.
23+
24+
## Using Github Codespaces
25+
If you want to use Github Codespaces you first of all need to configure your repository with a Codespace. For guides on how you can configure this, please the the [official documentation](https://docs.github.com/en/codespaces/developing-in-codespaces/creating-a-codespace-for-a-repository).
26+
27+
A Github Codespace is a development environment that’s hosted in the cloud. Codespaces run on a variety of VM-based compute options hosted by GitHub.com, which you can configure from 2 core machines up to 32 core machines. You can connect to your codespaces from the browser or locally using Visual Studio Code.
28+
29+
## Security in Development Containers
30+
Using development containers also opens up for some pretty nice features when it comes to security. In your traditional local development you install some local dependencies to make applications work, mix it with some application dependencies and suddenly you have a lot of installed artifacts that all can introduce security vulnerabilities. Some developers may also contribute on open source projects as well, introducing unknown application dependencies to be installed on your corporate device.
31+
32+
When using development containers you can scan and maintain your development environment with the same tools as you would with your application containers. Combine this with a CI/CD workflow and Snyk you can get build and vulnerability reports whenever there is a pull request that introduces new dependencies into the development environment, or you can run it periodically. To take it one step further you can also combine your development containers with tools like dependabot and get automated pull request against your development environment, as well as your application whenever there is a security update or a new version of a dependency.
33+
34+
## Working with external resources
35+
When working with development containers you can configure some atributes regarding port forwarding. Port forwarding is nessesary from your container to communicate with the ports your application exposes. One of the option in the `devcontainer.json` file is to automatically expose all ports from the container to the local host. When working with secure development we tend to not do this but rather define what port we need exposed. One of the big benefits with this is that you can have a QA or staging connection open on your local machine to a DB, but your development environment can't reach it as the port isn't exposed. This can be of great value if you forget that you have an open connection on a default port, say 5432 for PostgeSQL, so that a DB migration set to run on application boot dosen't modify the database unintentionally.
36+
37+
Another great feature with development containers is that you can install the dependencies and CLI's you would need to develop the application without it having to conflict with existing versions on your local machine. Let's say that you're working with an application running on AWS, then you can install the exact version of the CLI that's needed for that application. You can then also choose to define some configurations for the CLI, so say that your organisation have adopted the multi-account best practices from AWS, you can then have a dedicated container configured with AWS config for that account without it affecting your local configuration of the CLI.
38+
39+
Another feature that's worth highlighting is the benefits of working with secrets in the development containers. Say that your team has adopted a secrets manager like Vault or AWS Secrets Manager to store environment variables for your application, and that this is the case for all environments - including local development. You can then either combine this with the point above regarding CLI's configured to dedicated environments, or you can utilise the sections in `devcontainer.json` that allows you to run scripts on either the local machine or the remote container. This way the application can have the same configuration across environments without the need for multiple environment files, but your configuration file for the container has defined what the environment should be.
40+
41+
42+
## Guides and Documentation
43+
- [Official docs for Development Containers](https://containers.dev/)
44+
- [Github Org. for Development Containers](https://github.com/devcontainers)
45+
- [Starter Template for Develpoment Containers](https://github.com/devcontainers/template-starter)
46+
- [Security Champions Norway](https://securitychampions.no/)

dotnet/.gitignore

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
*.swp
2+
*.*~
3+
project.lock.json
4+
.DS_Store
5+
*.pyc
6+
nupkg/
7+
8+
# Visual Studio Code
9+
.vscode
10+
11+
# Rider
12+
.idea
13+
14+
# User-specific files
15+
*.suo
16+
*.user
17+
*.userosscache
18+
*.sln.docstates
19+
20+
# Build results
21+
[Dd]ebug/
22+
[Dd]ebugPublic/
23+
[Rr]elease/
24+
[Rr]eleases/
25+
x64/
26+
x86/
27+
build/
28+
bld/
29+
[Bb]in/
30+
[Oo]bj/
31+
[Oo]ut/
32+
msbuild.log
33+
msbuild.err
34+
msbuild.wrn
35+
36+
# Visual Studio 2015
37+
.vs/

dotnet/Classes/WeatherForecast.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace dotnet;
2+
3+
public class WeatherForecast
4+
{
5+
public DateOnly Date { get; set; }
6+
7+
public int TemperatureC { get; set; }
8+
9+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
10+
11+
public string? Summary { get; set; }
12+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
3+
namespace dotnet.Controllers;
4+
5+
[ApiController]
6+
[Route("[controller]")]
7+
public class SecurityChampionsController : ControllerBase
8+
{
9+
private readonly ILogger<SecurityChampionsController> _logger;
10+
11+
public SecurityChampionsController(ILogger<SecurityChampionsController> logger)
12+
{
13+
_logger = logger;
14+
}
15+
16+
[HttpGet(Name = "GetSecurityChampions")]
17+
public string Get()
18+
{
19+
return "Hello Security Champions meetup 3!👋🏻";
20+
}
21+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
3+
namespace dotnet.Controllers;
4+
5+
[ApiController]
6+
[Route("[controller]")]
7+
public class WeatherForecastController : ControllerBase
8+
{
9+
private static readonly string[] Summaries = new[]
10+
{
11+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
12+
};
13+
14+
private readonly ILogger<WeatherForecastController> _logger;
15+
16+
public WeatherForecastController(ILogger<WeatherForecastController> logger)
17+
{
18+
_logger = logger;
19+
}
20+
21+
[HttpGet(Name = "GetWeatherForecast")]
22+
public IEnumerable<WeatherForecast> Get()
23+
{
24+
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
25+
{
26+
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
27+
TemperatureC = Random.Shared.Next(-20, 55),
28+
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
29+
})
30+
.ToArray();
31+
}
32+
}

dotnet/Program.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var builder = WebApplication.CreateBuilder(args);
2+
3+
// Add services to the container.
4+
5+
builder.Services.AddControllers();
6+
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
7+
builder.Services.AddEndpointsApiExplorer();
8+
builder.Services.AddSwaggerGen();
9+
10+
var app = builder.Build();
11+
12+
// Configure the HTTP request pipeline.
13+
if (app.Environment.IsDevelopment())
14+
{
15+
app.UseSwagger();
16+
app.UseSwaggerUI();
17+
}
18+
19+
app.UseHttpsRedirection();
20+
21+
app.UseAuthorization();
22+
23+
app.MapControllers();
24+
25+
app.Run();

0 commit comments

Comments
 (0)