Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 113 additions & 57 deletions .github/workflows/createrelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,67 +73,123 @@
dotnet nuget push Nugets/SecurityService.IntegrationTesting.Helpers.${{ steps.get_version.outputs.VERSION }}.nupkg --api-key ${{ secrets.PRIVATEFEED_APIKEY }} --source ${{ secrets.PRIVATEFEED_URL }} --skip-duplicate

deploystaging:
runs-on: stagingserver
needs: buildlinux
environment: staging
name: "Deploy to Staging"

steps:
- name: Download the artifact
uses: actions/[email protected]
with:
name: securityservice

- name: Remove existing Windows service
run: |
$serviceName = "Transaction Processing - Security Service"
# Check if the service exists
if (Get-Service -Name $serviceName -ErrorAction SilentlyContinue) {
Stop-Service -Name $serviceName
sc.exe delete $serviceName
}

- name: Unzip the files
run: |
Expand-Archive -Path securityservice.zip -DestinationPath "C:\txnproc\transactionprocessing\securityservice" -Force

- name: Install as a Windows service
run: |
$serviceName = "Transaction Processing - Security Service"
$servicePath = "C:\txnproc\transactionprocessing\securityservice\SecurityService.exe"

New-Service -Name $serviceName -BinaryPathName $servicePath -Description "Transaction Processing - Security Service" -DisplayName "Transaction Processing - Security Service" -StartupType Automatic
Start-Service -Name $serviceName
runs-on: [stagingserver, linux]
needs: buildlinux
environment: staging
name: "Deploy to Staging"

steps:
- name: Download the artifact
uses: actions/[email protected]
with:
name: securityservice
path: /tmp/securityservice # Download to a temporary directory

- name: Remove existing service (if applicable)
run: |
SERVICE_NAME="securityservice" # Or whatever your service will be called
if systemctl is-active --quiet "$SERVICE_NAME"; then
echo "Stopping existing service..."
sudo systemctl stop "$SERVICE_NAME"
fi
if systemctl is-enabled --quiet "$SERVICE_NAME"; then
echo "Disabling existing service..."
sudo systemctl disable "$SERVICE_NAME"
fi
if [ -f "/etc/systemd/system/${SERVICE_NAME}.service" ]; then
echo "Removing existing service unit file..."
sudo rm "/etc/systemd/system/${SERVICE_NAME}.service"
sudo systemctl daemon-reload
fi

- name: Unzip the files
run: |
mkdir -p /opt/txnproc/transactionprocessing/securityservice
unzip -o /tmp/securityservice/securityservice.zip -d /opt/txnproc/transactionprocessing/securityservice

- name: Install and Start as a Linux service
run: |
SERVICE_NAME="securityservice"
EXEC_PATH="/opt/txnproc/transactionprocessing/securityservice/SecurityService" # Assuming your executable is named SecurityService
SERVICE_DESCRIPTION="Transaction Processing - Security Service"

# Create a systemd service file
echo "[Unit]" | sudo tee /etc/systemd/system/${SERVICE_NAME}.service
echo "Description=${SERVICE_DESCRIPTION}" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
echo "After=network.target" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
echo "" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
echo "[Service]" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
echo "ExecStart=${EXEC_PATH}" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
echo "Restart=always" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
echo "User=youruser" # Consider running as a less privileged user
echo "Group=yourgroup" # Consider running as a less privileged group
echo "" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
echo "[Install]" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
echo "WantedBy=multi-user.target" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service

# Reload systemd, enable, and start the service
sudo systemctl daemon-reload
sudo systemctl enable "$SERVICE_NAME"
sudo systemctl start "$SERVICE_NAME"
sudo systemctl status "$SERVICE_NAME" --no-pager # For debugging/verification

deployproduction:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {}
runs-on: productionserver
runs-on: [productionserver, linux]
needs: [buildlinux, deploystaging]
environment: production
name: "Deploy to Production"

steps:
- name: Download the artifact
uses: actions/[email protected]
with:
name: securityservice

- name: Remove existing Windows service
run: |
$serviceName = "Transaction Processing - Security Service"
# Check if the service exists
if (Get-Service -Name $serviceName -ErrorAction SilentlyContinue) {
Stop-Service -Name $serviceName
sc.exe delete $serviceName
}

- name: Unzip the files
run: |
Expand-Archive -Path securityservice.zip -DestinationPath "C:\txnproc\transactionprocessing\securityservice" -Force

- name: Install as a Windows service
run: |
$serviceName = "Transaction Processing - Security Service"
$servicePath = "C:\txnproc\transactionprocessing\securityservice\SecurityService.exe"

New-Service -Name $serviceName -BinaryPathName $servicePath -Description "Transaction Processing - Security Service" -DisplayName "Transaction Processing - Security Service" -StartupType Automatic
Start-Service -Name $serviceName
- name: Download the artifact
uses: actions/[email protected]
with:
name: securityservice
path: /tmp/securityservice # Download to a temporary directory

- name: Remove existing service (if applicable)
run: |
SERVICE_NAME="securityservice" # Or whatever your service will be called
if systemctl is-active --quiet "$SERVICE_NAME"; then
echo "Stopping existing service..."
sudo systemctl stop "$SERVICE_NAME"
fi
if systemctl is-enabled --quiet "$SERVICE_NAME"; then
echo "Disabling existing service..."
sudo systemctl disable "$SERVICE_NAME"
fi
if [ -f "/etc/systemd/system/${SERVICE_NAME}.service" ]; then
echo "Removing existing service unit file..."
sudo rm "/etc/systemd/system/${SERVICE_NAME}.service"
sudo systemctl daemon-reload
fi

- name: Unzip the files
run: |
mkdir -p /opt/txnproc/transactionprocessing/securityservice
unzip -o /tmp/securityservice/securityservice.zip -d /opt/txnproc/transactionprocessing/securityservice

- name: Install and Start as a Linux service
run: |
SERVICE_NAME="securityservice"
EXEC_PATH="/opt/txnproc/transactionprocessing/securityservice/SecurityService" # Assuming your executable is named SecurityService
SERVICE_DESCRIPTION="Transaction Processing - Security Service"

# Create a systemd service file
echo "[Unit]" | sudo tee /etc/systemd/system/${SERVICE_NAME}.service
echo "Description=${SERVICE_DESCRIPTION}" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
echo "After=network.target" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
echo "" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
echo "[Service]" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
echo "ExecStart=${EXEC_PATH}" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
echo "Restart=always" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
echo "User=youruser" # Consider running as a less privileged user
echo "Group=yourgroup" # Consider running as a less privileged group
echo "" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
echo "[Install]" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
echo "WantedBy=multi-user.target" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service

# Reload systemd, enable, and start the service
sudo systemctl daemon-reload
sudo systemctl enable "$SERVICE_NAME"
sudo systemctl start "$SERVICE_NAME"
sudo systemctl status "$SERVICE_NAME" --no-pager # For debugging/verification
Comment on lines +137 to +195

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {}

Copilot Autofix

AI 10 months ago

To fix the issue, we need to add a permissions block to the workflow file. This block should specify the least privileges required for the workflow to function correctly. Since the workflow involves deploying artifacts and pushing NuGet packages, we can set contents: read for accessing repository contents and packages: write for pushing packages. Other permissions can be omitted unless explicitly required.

The permissions block can be added at the root level of the workflow to apply to all jobs or within individual jobs to tailor permissions for specific tasks.

Suggested changeset 1
.github/workflows/createrelease.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/createrelease.yml b/.github/workflows/createrelease.yml
--- a/.github/workflows/createrelease.yml
+++ b/.github/workflows/createrelease.yml
@@ -6,2 +6,6 @@
 
+permissions:
+  contents: read
+  packages: write
+
 jobs:
EOF
@@ -6,2 +6,6 @@

permissions:
contents: read
packages: write

jobs:
Copilot is powered by AI and may make mistakes. Always verify output.
Binary file modified Certificates/aspnetapp-identity-server.pfx
Binary file not shown.
Binary file modified Certificates/aspnetapp-root-cert.cer
Binary file not shown.
Binary file modified Certificates/aspnetapp-root-cert.pfx
Binary file not shown.
Binary file modified Certificates/aspnetapp-web-api.pfx
Binary file not shown.
Binary file modified SecurityService/aspnetapp-root-cert.cer
Binary file not shown.
Binary file modified SecurityService/aspnetapp-web-api.pfx
Binary file not shown.
Loading