diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 00000000..48f938d2 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,94 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL Advanced" + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + schedule: + - cron: '38 1 * * 5' + +jobs: + analyze: + name: Analyze (${{ matrix.language }}) + # Runner size impacts CodeQL analysis time. To learn more, please see: + # - https://gh.io/recommended-hardware-resources-for-running-codeql + # - https://gh.io/supported-runners-and-hardware-resources + # - https://gh.io/using-larger-runners (GitHub.com only) + # Consider using larger runners or machines with greater resources for possible analysis time improvements. + runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} + permissions: + # required for all workflows + security-events: write + + # required to fetch internal or private CodeQL packs + packages: read + + # only required for workflows in private repositories + actions: read + contents: read + + strategy: + fail-fast: false + matrix: + include: + - language: csharp + build-mode: none + - language: ruby + build-mode: none + # CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' + # Use `c-cpp` to analyze code written in C, C++ or both + # Use 'java-kotlin' to analyze code written in Java, Kotlin or both + # Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both + # To learn more about changing the languages that are analyzed or customizing the build mode for your analysis, + # see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning. + # If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how + # your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: ${{ matrix.language }} + build-mode: ${{ matrix.build-mode }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality + + # If the analyze step fails for one of the languages you are analyzing with + # "We were unable to automatically build your code", modify the matrix above + # to set the build mode to "manual" for that language. Then modify this step + # to build your code. + # ℹ️ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + - if: matrix.build-mode == 'manual' + shell: bash + run: | + echo 'If you are using a "manual" build mode for one or more of the' \ + 'languages you are analyzing, replace this with the commands to build' \ + 'your code, for example:' + echo ' make bootstrap' + echo ' make release' + exit 1 + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 + with: + category: "/language:${{matrix.language}}" diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 00000000..b6222667 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,47 @@ +name: Deploy Azure Resources + +on: + workflow_dispatch: + inputs: + environment: + description: 'Environment to deploy to' + required: true + default: 'dev' + +permissions: + id-token: write + contents: read + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Azure CLI + uses: azure/login@v2 + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + enable-AzPSSession: true + + - name: Set deployment name + id: set-deployment-name + run: echo "##[set-output name=deployment_name;]deployment-$(date +%s)" + + - name: Deploy Bicep file + run: | + az deployment group create \ + --resource-group ${{ secrets.AZURE_RG }} \ + --name ${{ steps.set-deployment-name.outputs.deployment_name }} \ + --template-file src/InfrastructureAsCode/main.bicep \ + --parameters environment=${{ github.event.inputs.environment }} + + - name: Output results + run: | + echo "App Service Name: $(az deployment group show --resource-group ${{ secrets.AZURE_RG }} --name ${{ steps.set-deployment-name.outputs.deployment_name }} --query properties.outputs.appServiceName.value -o tsv)" + echo "App Service URL: $(az deployment group show --resource-group ${{ secrets.AZURE_RG }} --name ${{ steps.set-deployment-name.outputs.deployment_name }} --query properties.outputs.appServiceUrl.value -o tsv)" + echo "Container Registry Name: $(az deployment group show --resource-group ${{ secrets.AZURE_RG }} --name ${{ steps.set-deployment-name.outputs.deployment_name }} --query properties.outputs.containerRegistryName.value -o tsv)" \ No newline at end of file diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml new file mode 100644 index 00000000..a42a3929 --- /dev/null +++ b/.github/workflows/dotnet.yml @@ -0,0 +1,130 @@ +# This workflow will build a .NET project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net + +name: .NET + +on: + push: + branches: [ "main" ] + paths: + - 'src/Application/**' + pull_request: + branches: [ "main" ] + paths: + - 'src/Application/**' + workflow_dispatch: + + +permissions: + id-token: write + contents: read + +env: + registryName: "q3zpru2gmy754mpnpreg.azurecr.io" # Replace registryName with the name of your registry + repositoryName: "techexcel/dotnetcoreapp" + dockerFolderPath: "src/Application/src/RazorPagesTestSample" + tag: ${{ github.run_number }} + +jobs: + build: + + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + - name: Restore dependencies + run: dotnet restore src/Application/src/RazorPagesTestSample/RazorPagesTestSample.csproj + - name: Build + run: dotnet build src/Application/src/RazorPagesTestSample/RazorPagesTestSample.csproj --no-restore + - name: Test + run: dotnet test src/Application/tests/RazorPagesTestSample.Tests/RazorPagesTestSample.Tests.csproj --no-build --verbosity normal + + buildacr: + runs-on: ubuntu-latest + needs: build + steps: + - uses: actions/checkout@v4 + + - name: Login to Azure Container Registry + run: echo "${{ secrets.ACR_PASSWORD }}" | docker login ${{ env.registryName }} -u ${{ secrets.ACR_USERNAME }} --password-stdin + + - name: Build and push Docker image + run: | + docker build ${{ env.dockerFolderPath }} -t ${{ env.registryName }}/${{ env.repositoryName }}:${{ env.tag }} + docker push ${{ env.registryName }}/${{ env.repositoryName }}:${{ env.tag }} + + deploytodev: + runs-on: ubuntu-latest + needs: buildacr + environment: dev + + steps: + - uses: actions/checkout@v4 + + - name: Azure Login + uses: azure/login@v2 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + + - name: Deploy to Azure Web App + run: | + az webapp config container set \ + --name q3zpru2gmy754-dev \ + --resource-group ${{ secrets.AZURE_RG }} \ + --docker-custom-image-name ${{ env.registryName }}/${{ env.repositoryName }}:${{ env.tag }} \ + --docker-registry-server-url https://${{ env.registryName }} \ + --docker-registry-server-user ${{ secrets.ACR_USERNAME }} \ + --docker-registry-server-password ${{ secrets.ACR_PASSWORD }} + + + deploytotest: + runs-on: ubuntu-latest + needs: deploytodev + environment: test + + steps: + - uses: actions/checkout@v4 + + - name: Azure Login + uses: azure/login@v2 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + + - name: Deploy to Azure Web App + run: | + az webapp config container set \ + --name q3zpru2gmy754-test \ + --resource-group ${{ secrets.AZURE_RG }} \ + --docker-custom-image-name ${{ env.registryName }}/${{ env.repositoryName }}:${{ env.tag }} \ + --docker-registry-server-url https://${{ env.registryName }} \ + --docker-registry-server-user ${{ secrets.ACR_USERNAME }} \ + --docker-registry-server-password ${{ secrets.ACR_PASSWORD }} + + deploytoprod: + runs-on: ubuntu-latest + needs: deploytotest + environment: prod + + steps: + - uses: actions/checkout@v4 + + - name: Azure Login + uses: azure/login@v2 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + + - name: Deploy to Azure Web App + run: | + az webapp config container set \ + --name q3zpru2gmy754-prod \ + --resource-group ${{ secrets.AZURE_RG }} \ + --docker-custom-image-name ${{ env.registryName }}/${{ env.repositoryName }}:${{ env.tag }} \ + --docker-registry-server-url https://${{ env.registryName }} \ + --docker-registry-server-user ${{ secrets.ACR_USERNAME }} \ + --docker-registry-server-password ${{ secrets.ACR_PASSWORD }} \ No newline at end of file diff --git a/.github/workflows/first-workflow.yml b/.github/workflows/first-workflow.yml new file mode 100644 index 00000000..e1675e19 --- /dev/null +++ b/.github/workflows/first-workflow.yml @@ -0,0 +1,29 @@ +name: Manual Trigger Workflow + +on: + workflow_dispatch: + issues: + types: [opened] + +jobs: + + job1: + runs-on: ubuntu-latest + + steps: + - name: Step 1 + run: echo "Step 1 complete!" + + - name: Step 2 + run: echo "Step 2 complete!" + + job2: + needs: job1 + runs-on: ubuntu-latest + + steps: + - name: Cowsays Action + uses: mscoutermarsh/cowsays-action@master + with: + text: "Ready for prod–ship it!" + color: magenta \ No newline at end of file diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml deleted file mode 100644 index cedae546..00000000 --- a/.github/workflows/pages.yml +++ /dev/null @@ -1,62 +0,0 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -# Sample workflow for building and deploying a Jekyll site to GitHub Pages -name: Deploy Jekyll site to Pages - -on: - push: - branches: ["main"] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages -permissions: - contents: read - pages: write - id-token: write - -# Allow one concurrent deployment -concurrency: - group: "pages" - cancel-in-progress: true - -jobs: - # Build job - build: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Setup Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: '3.1' # Not needed with a .ruby-version file - bundler-cache: true # runs 'bundle install' and caches installed gems automatically - cache-version: 0 # Increment this number if you need to re-download cached gems - - name: Setup Pages - id: pages - uses: actions/configure-pages@v2 - - name: Build with Jekyll - # Outputs to the './_site' directory by default - run: bundle exec jekyll build --baseurl "${{ steps.pages.outputs.base_path }}" - env: - JEKYLL_ENV: production - - name: Upload artifact - # Automatically uploads an artifact from the './_site' directory by default - uses: actions/upload-pages-artifact@v1 - - # Deployment job - deploy: - environment: - name: github-pages - url: "${{ steps.deployment.outputs.page_url }}" - runs-on: ubuntu-latest - needs: build - steps: - - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@v1 diff --git a/SECURITY.md b/SECURITY.md index b3c89efc..04c20a6f 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -39,3 +39,33 @@ We prefer all communications to be in English. Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/security.md/cvd). +# Security Policy + +## Supported Versions + +We release patches for security vulnerabilities. Which versions are eligible for receiving such patches depends on the CVSS v3.0 Rating: + +| Version | Supported | +| ------- | ------------------ | +| 1.0.x | :white_check_mark: | +| < 1.0 | :x: | + +## Reporting a Vulnerability + +If you discover a security vulnerability, please follow these steps: + +1. **Do not open an issue**: This ensures that the vulnerability is not publicly disclosed before a fix is available. +2. **Send an email to [security@example.com](mailto:security@example.com)**: Provide as much detail as possible about the vulnerability and how it can be exploited. +3. **Expect a response within 48 hours**: We will acknowledge the receipt of your report and provide a timeline for a fix. + +## Security Updates + +We will notify users about security updates through: + +- GitHub Releases +- Email notifications (if subscribed) + +## Security Resources + +- [OWASP Top Ten](https://owasp.org/www-project-top-ten/) +- [CWE/SANS Top 25](https://cwe.mitre.org/top25/archive/2020/2020_cwe_top25.html) \ No newline at end of file diff --git a/src/Application/CODEOWNERS b/src/Application/CODEOWNERS new file mode 100644 index 00000000..a89a9d99 --- /dev/null +++ b/src/Application/CODEOWNERS @@ -0,0 +1,5 @@ +# This is a comment +# Each line is a file pattern followed by one or more owners + +# Specify a default code owner for the entire repository +* @ahmedsza diff --git a/src/Application/src/RazorPagesTestSample/Data/Message.cs b/src/Application/src/RazorPagesTestSample/Data/Message.cs index ea99cbd6..979252d8 100644 --- a/src/Application/src/RazorPagesTestSample/Data/Message.cs +++ b/src/Application/src/RazorPagesTestSample/Data/Message.cs @@ -3,14 +3,24 @@ namespace RazorPagesTestSample.Data { #region snippet1 + /// + /// Represents a message entity with a maximum length of 250 characters. + /// public class Message { + /// + /// Gets or sets the unique identifier for the message. + /// public int Id { get; set; } + /// + /// Gets or sets the text of the message. + /// The text is required and has a maximum length of 250 characters. + /// [Required] [DataType(DataType.Text)] - [StringLength(200, ErrorMessage = "There's a 200 character limit on messages. Please shorten your message.")] + [StringLength(250, ErrorMessage = "There's a 250 character limit on messages. Please shorten your message.")] public string Text { get; set; } } #endregion -} +} \ No newline at end of file diff --git a/src/Application/src/RazorPagesTestSample/Dockerfile b/src/Application/src/RazorPagesTestSample/Dockerfile new file mode 100644 index 00000000..30b11996 --- /dev/null +++ b/src/Application/src/RazorPagesTestSample/Dockerfile @@ -0,0 +1,22 @@ +# Update the base and SDK images to .NET 8 +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base +WORKDIR /app +EXPOSE 80 +ENV ASPNETCORE_URLS=http://+:80 + + +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +WORKDIR /src +COPY ["RazorPagesTestSample.csproj", "./"] +RUN dotnet restore "./RazorPagesTestSample.csproj" +COPY . . +WORKDIR "/src/." +RUN dotnet build "RazorPagesTestSample.csproj" -c Release -o /app/build + +FROM build AS publish +RUN dotnet publish "RazorPagesTestSample.csproj" -c Release -o /app/publish + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "RazorPagesTestSample.dll"] \ No newline at end of file diff --git a/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml b/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml index f7645733..ba4d74c0 100644 --- a/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml +++ b/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml @@ -1,7 +1,7 @@ @page @model IndexModel @{ - ViewData["Title"] = "Munson's Pickles and Preserves Team Messaging System"; + ViewData["Title"] = "Munson's Pickles and Preserves Team Messaging System with PR"; }

@ViewData["Title"]

diff --git a/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml.cs b/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml.cs index 2e6d94bb..04ba785e 100644 --- a/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml.cs +++ b/src/Application/src/RazorPagesTestSample/Pages/Index.cshtml.cs @@ -74,9 +74,9 @@ public async Task OnPostAnalyzeMessagesAsync() { // Speed loop. Lower this number once every quarter so we // get our performance improvement quarterly bonus. - for (int i = 0; i < 3000; i++) { - Thread.Sleep(1); - } + // for (int i = 0; i < 3000; i++) { + // Thread.Sleep(1); + // } var wordCount = 0; diff --git a/src/InfrastructureAsCode/main.bicep b/src/InfrastructureAsCode/main.bicep index 6dc69618..cdd9f13b 100644 --- a/src/InfrastructureAsCode/main.bicep +++ b/src/InfrastructureAsCode/main.bicep @@ -14,4 +14,97 @@ var registrySku = 'Standard' var imageName = 'techexcel/dotnetcoreapp' var startupCommand = '' -// TODO: complete this script +// Create Log Analytics Workspace +resource logAnalytics 'Microsoft.OperationalInsights/workspaces@2021-06-01' = { + name: logAnalyticsName + location: location + properties: { + sku: { + name: 'PerGB2018' + } + retentionInDays: 30 + } +} + +// Create Application Insights +resource appInsights 'Microsoft.Insights/components@2020-02-02' = { + name: appInsightsName + location: location + kind: 'web' + properties: { + Application_Type: 'web' + WorkspaceResourceId: logAnalytics.id + } +} + +// Create Azure Container Registry +resource containerRegistry 'Microsoft.ContainerRegistry/registries@2021-06-01-preview' = { + name: registryName + location: location + sku: { + name: registrySku + } + properties: { + adminUserEnabled: true + } +} + +// Create App Service Plan +resource appServicePlan 'Microsoft.Web/serverfarms@2021-02-01' = { + name: appServicePlanName + location: location + sku: { + name: sku + tier: 'Standard' + } + properties: { + reserved: true // This property is required for Linux + } +} + +// Create Web App +resource webApp 'Microsoft.Web/sites@2021-02-01' = { + name: webAppName + location: location + properties: { + serverFarmId: appServicePlan.id + siteConfig: { + linuxFxVersion: 'DOCKER|${imageName}' + appSettings: [ + { + name: 'DOCKER_REGISTRY_SERVER_URL' + value: 'https://${registryName}.azurecr.io' + } + { + name: 'DOCKER_REGISTRY_SERVER_USERNAME' + value: containerRegistry.properties.adminUserEnabled ? listCredentials(containerRegistry.id, '2021-06-01-preview').username : '' + } + { + name: 'DOCKER_REGISTRY_SERVER_PASSWORD' + value: containerRegistry.properties.adminUserEnabled ? listCredentials(containerRegistry.id, '2021-06-01-preview').passwords[0].value : '' + } + { + name: 'APPINSIGHTS_INSTRUMENTATIONKEY' + value: appInsights.properties.InstrumentationKey + } + { + name: 'APPLICATIONINSIGHTS_CONNECTION_STRING' + value: appInsights.properties.ConnectionString + } + { + name: 'WEBSITES_ENABLE_APP_SERVICE_STORAGE' + value: 'false' + } + { + name: 'WEBSITES_PORT' + value: '80' // Default port for your application + } + ] + } + } +} + +// Outputs +output appServiceName string = webApp.name +output appServiceUrl string = 'https://${webAppName}.azurewebsites.net' +output containerRegistryName string = containerRegistry.name