diff --git a/.gitignore b/.gitignore index 9e1210e7..1576fba0 100644 --- a/.gitignore +++ b/.gitignore @@ -44,4 +44,9 @@ JsonStorage.json *.crt *.pem *.key -*.cnf \ No newline at end of file +*.cnf + +# Azurite local storage files +__azurite_db_* +__blobstorage__ +__queuestorage__ diff --git a/api/.env.example b/api/.env.example new file mode 100644 index 00000000..352ed8fb --- /dev/null +++ b/api/.env.example @@ -0,0 +1,71 @@ +########################################## +# Environment Variables for CodePush Server +########################################## + +# ============================== +# Storage Configuration (REQUIRED - choose one) +# ============================== +EMULATED=false # Set to 'true' to use the local emulator + +# --- Azure Storage Configuration --- +AZURE_STORAGE_ACCOUNT= # Azure storage account name +AZURE_STORAGE_ACCESS_KEY= # Azure storage access key (if KeyVault not used) + +# ============================== +# Server Configuration (REQUIRED) +# ============================== +SERVER_URL=http://localhost:3000 # The URL of your server + +# ============================== +# Authentication (REQUIRED - at least one provider) +# ============================== + +# --- GitHub OAuth --- +GITHUB_CLIENT_ID= # GitHub OAuth client ID +GITHUB_CLIENT_SECRET= # GitHub OAuth client secret + +# --- Microsoft OAuth --- +MICROSOFT_CLIENT_ID= # Microsoft OAuth client ID +MICROSOFT_CLIENT_SECRET= # Microsoft OAuth client secret + +# ============================== +# Optional Configuration +# ============================== + +# --- HTTPS Configuration --- +HTTPS= # Set to 'true' to enable HTTPS for local deployment + +# --- Debugging Configuration --- +LOGGING=false # Enable CodePush-specific logging +DEBUG_DISABLE_AUTH=false # Disable OAuth authentication route +DEBUG_USER_ID= # Backend user ID for debugging session + +# ============================== +# Redis Configuration +# ============================== +REDIS_HOST= # Redis server IP address +REDIS_PORT=6379 # Redis port (default: 6379) +REDIS_KEY= # Redis authentication key + +# ============================== +# Unit Testing Configuration +# ============================== +TEST_AZURE_STORAGE=false # Run API unit tests against Azure storage +AZURE_ACQUISITION_URL= # URL for acquisition tests + +# ============================== +# Other Configuration +# ============================== +DISABLE_ACQUISITION=false # Disable acquisition routes +DISABLE_MANAGEMENT=false # Disable management routes +ENABLE_ACCOUNT_REGISTRATION=true # Enable account registration +UPLOAD_SIZE_LIMIT_MB=200 # Max file upload size (in MB) +ENABLE_PACKAGE_DIFFING=false # Enable generating diffs for releases + +# ============================== +# Azure KeyVault Configuration (Optional) +# ============================== +AZURE_KEYVAULT_ACCOUNT= # Azure KeyVault account name +CLIENT_ID= # Active Directory app client ID +CERTIFICATE_THUMBPRINT= # AD app certificate thumbprint +REFRESH_CREDENTIALS_INTERVAL=86400000 # Credential refresh interval (in ms, default: 1 day) diff --git a/api/ENVIRONMENT.md b/api/ENVIRONMENT.md index 0f4067e6..c16f1405 100644 --- a/api/ENVIRONMENT.md +++ b/api/ENVIRONMENT.md @@ -2,7 +2,7 @@ The CodePush Server is configured using environment variables. -Currently, the following environment variables are available. For convenience, we will also load the server environment from any '.env' file in the api directory, and the test environment from any '.test.env' file in the root directory. +For convenience, we will also load the server environment from any '.env' file in the api directory, and the test environment from any '.test.env' file in the root directory. Use the `.env.example` file as a template for setting up your environment variables. ## Mandatory parameters diff --git a/api/README.md b/api/README.md index b9747afd..e8f042c3 100644 --- a/api/README.md +++ b/api/README.md @@ -16,11 +16,26 @@ Additionally, you need to specify [EMULATED](ENVIRONMENT.md#emulated) flag equal #### Steps To run the CodePush Server locally, follow these steps: -1. Clone the CodePush Service repository. -1. Create a `.env` file and configure the mandatory variables as outlined in the `ENVIRONMENT.md` file. -1. Install dependencies by running `npm install`. -1. Build the server by running `npm run build`. -1. Start the server by running `npm run start:env`. + +1. Clone the CodePush Service repository to your local machine. + +2. Copy the `.env.example` file to a new file named `.env` in the root directory: + ````bash + cp .env.example .env + ```` + Fill in the values for each environment variable in the `.env` file according to your development or production setup. +3. Install all necessary dependencies: + ````bash + npm install + ```` +4. Compile the server code: + ````bash + npm run build + ```` +5. Launch the server with the environment-specific start command: + ````bash + npm run start:env + ```` By default, local CodePush server runs on HTTP. To run CodePush Server on HTTPS: @@ -115,3 +130,15 @@ Both work and personal accounts use the same application for authentication. The 1. Only letters are allowed. 1. Maximum 15 characters. + +## Metrics + +Installation metrics allow monitoring release activity via the CLI. For detailed usage instructions, please refer to the [CLI documentation](../cli/README.md#development-parameter). + +Redis is required for Metrics to work. + +### Steps + +1. Install Redis by following [official installation guide](https://redis.io/docs/latest/operate/oss_and_stack/install/install-redis/). +1. TLS is required. Follow [official Redis TLS run guide](https://redis.io/docs/latest/operate/oss_and_stack/management/security/encryption/#running-manually). +1. Set the necessary environment variables for [Redis](./ENVIRONMENT.md#redis). \ No newline at end of file diff --git a/api/SECURITY.md b/api/SECURITY.md index 2ee12dc5..022413d5 100644 --- a/api/SECURITY.md +++ b/api/SECURITY.md @@ -19,4 +19,4 @@ All secrets used in the system should be handled with the utmost care. They must It is essential to review and apply security best practices for all system components. As this setup is minimal, it is the customer’s responsibility to harden the system for production use. - [Azure Storage Security Recommendations](https://learn.microsoft.com/en-us/azure/storage/blobs/security-recommendations) -- [Azure WebApp Security Best Practices](https://learn.microsoft.com/en-us/azure/app-service/overview-security) +- [Azure WebApp Security Best Practices](https://learn.microsoft.com/en-us/azure/app-service/overview-security) \ No newline at end of file diff --git a/api/package-lock.json b/api/package-lock.json index 4575bed7..df50d9dc 100644 --- a/api/package-lock.json +++ b/api/package-lock.json @@ -18,7 +18,7 @@ "cookie-session": "^2.0.0", "ejs": "^3.1.10", "email-validator": "1.0.3", - "express": "^4.19.2", + "express": "^4.21.1", "express-domain-middleware": "0.1.0", "express-rate-limit": "^7.4.0", "multer": "^1.4.5-lts.1", @@ -2031,9 +2031,9 @@ } }, "node_modules/cookie": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.6.0.tgz", - "integrity": "sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==", + "version": "0.7.1", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.1.tgz", + "integrity": "sha512-6DnInpx7SJ2AK3+CTUE/ZM0vWTUboZCegxhC2xiIydHR9jNuTAASBrfEpHhiGOZw/nX51bHt6YQl8jsGo4y/0w==", "engines": { "node": ">= 0.6" } @@ -2671,16 +2671,16 @@ } }, "node_modules/express": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/express/-/express-4.21.0.tgz", - "integrity": "sha512-VqcNGcj/Id5ZT1LZ/cfihi3ttTn+NJmkli2eZADigjq29qTlWi/hAQ43t/VLPq8+UX06FCEx3ByOYet6ZFblng==", + "version": "4.21.1", + "resolved": "https://registry.npmjs.org/express/-/express-4.21.1.tgz", + "integrity": "sha512-YSFlK1Ee0/GC8QaO91tHcDxJiE/X4FbpAyQWkxAvG6AXCuR65YzK8ua6D9hvi/TzUfZMpc+BwuM1IPw8fmQBiQ==", "dependencies": { "accepts": "~1.3.8", "array-flatten": "1.1.1", "body-parser": "1.20.3", "content-disposition": "0.5.4", "content-type": "~1.0.4", - "cookie": "0.6.0", + "cookie": "0.7.1", "cookie-signature": "1.0.6", "debug": "2.6.9", "depd": "2.0.0", diff --git a/api/package.json b/api/package.json index 549e859e..8adc3b7f 100644 --- a/api/package.json +++ b/api/package.json @@ -32,7 +32,7 @@ "cookie-session": "^2.0.0", "ejs": "^3.1.10", "email-validator": "1.0.3", - "express": "^4.19.2", + "express": "^4.21.1", "express-domain-middleware": "0.1.0", "express-rate-limit": "^7.4.0", "multer": "^1.4.5-lts.1", diff --git a/api/script/routes/passport-authentication.ts b/api/script/routes/passport-authentication.ts index 488d0d75..46bb8f28 100644 --- a/api/script/routes/passport-authentication.ts +++ b/api/script/routes/passport-authentication.ts @@ -167,17 +167,17 @@ export class PassportAuthentication { router.get("/auth/login", this._cookieSessionMiddleware, (req: Request, res: Response): any => { req.session["hostname"] = req.query.hostname; - res.render("authenticate", { action: "login" }); + res.render("authenticate", { action: "login", isGitHubAuthenticationEnabled, isMicrosoftAuthenticationEnabled }); }); router.get("/auth/link", this._cookieSessionMiddleware, (req: Request, res: Response): any => { req.session["authorization"] = req.query.access_token; - res.render("authenticate", { action: "link" }); + res.render("authenticate", { action: "link", isGitHubAuthenticationEnabled, isMicrosoftAuthenticationEnabled }); }); router.get("/auth/register", this._cookieSessionMiddleware, (req: Request, res: Response): any => { req.session["hostname"] = req.query.hostname; - res.render("authenticate", { action: "register" }); + res.render("authenticate", { action: "register", isGitHubAuthenticationEnabled, isMicrosoftAuthenticationEnabled }); }); return router; diff --git a/api/script/views/authenticate.ejs b/api/script/views/authenticate.ejs index cb621898..33251b46 100644 --- a/api/script/views/authenticate.ejs +++ b/api/script/views/authenticate.ejs @@ -85,11 +85,15 @@