From 7830184993a2624a2aae4515676d1324fab76594 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Wed, 16 Nov 2016 14:27:18 +0800 Subject: Create s3 config guide --- docs/guides/s3-image-upload.md | 62 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 docs/guides/s3-image-upload.md (limited to 'docs/guides/s3-image-upload.md') diff --git a/docs/guides/s3-image-upload.md b/docs/guides/s3-image-upload.md new file mode 100644 index 00000000..4c9faded --- /dev/null +++ b/docs/guides/s3-image-upload.md @@ -0,0 +1,62 @@ +# Guide - Setup HackMD S3 image upload + +1. Go to [AWS S3 console](https://console.aws.amazon.com/s3/home) and create a new bucket. + + ![create-bucket](images/s3-image-upload/create-bucket.png) + +2. Click on bucket, select **Properties** on the side panel, and find **Permission** section. Click **Edit bucket policy**. + + ![bucket-property](images/s3-image-upload/bucket-property.png) + +3. Enter the following policy, replace `bucket_name` with your bucket name: + + ![bucket-policy-editor](images/s3-image-upload/bucket-policy-editor.png) + +```json +{ + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Principal": "*", + "Action": "s3:GetObject", + "Resource": "arn:aws:s3:::bucket_name/uploads/*" + } + ] +} +``` + +4. Go to IAM console and create a new IAM user. Remember your user credentials(`key`/`access token`) + +5. Enter user page, select **Permission** tab, look at **Inline Policies** section, and click **Create User Policy** + + ![iam-user](images/s3-image-upload/iam-user.png) + +6. Select **Custom Policy** + + ![custom-policy](images/s3-image-upload/custom-policy.png) + +7. Enter the following policy, replace `bucket_name` with your bucket name: + + ![review-policy](images/s3-image-upload/review-policy.png) + +```json +{ + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "s3:*" + ], + "Resource": [ + "arn:aws:s3:::bucket_name/uploads/*" + ] + } + ] +} +``` + +## Related Tools + +* [AWS Policy Generator](http://awspolicygen.s3.amazonaws.com/policygen.html) -- cgit v1.3.1 From 1f409197c350f04caf878d0e8926d5edd882f4f5 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Wed, 16 Nov 2016 14:46:38 +0800 Subject: Fix order list --- docs/guides/s3-image-upload.md | 58 +++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 29 deletions(-) (limited to 'docs/guides/s3-image-upload.md') diff --git a/docs/guides/s3-image-upload.md b/docs/guides/s3-image-upload.md index 4c9faded..c92e91f8 100644 --- a/docs/guides/s3-image-upload.md +++ b/docs/guides/s3-image-upload.md @@ -12,19 +12,19 @@ ![bucket-policy-editor](images/s3-image-upload/bucket-policy-editor.png) -```json -{ - "Version": "2012-10-17", - "Statement": [ - { - "Effect": "Allow", - "Principal": "*", - "Action": "s3:GetObject", - "Resource": "arn:aws:s3:::bucket_name/uploads/*" - } - ] -} -``` + ```json + { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Principal": "*", + "Action": "s3:GetObject", + "Resource": "arn:aws:s3:::bucket_name/uploads/*" + } + ] + } + ``` 4. Go to IAM console and create a new IAM user. Remember your user credentials(`key`/`access token`) @@ -40,22 +40,22 @@ ![review-policy](images/s3-image-upload/review-policy.png) -```json -{ - "Version": "2012-10-17", - "Statement": [ - { - "Effect": "Allow", - "Action": [ - "s3:*" - ], - "Resource": [ - "arn:aws:s3:::bucket_name/uploads/*" - ] - } - ] -} -``` + ```json + { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "s3:*" + ], + "Resource": [ + "arn:aws:s3:::bucket_name/uploads/*" + ] + } + ] + } + ``` ## Related Tools -- cgit v1.3.1 From aaf034bfbc7b0b4ac6153b8fefdc04d10a9f0c1f Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Thu, 17 Nov 2016 18:13:57 +0800 Subject: Update README --- README.md | 7 +++++++ docs/guides/s3-image-upload.md | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) (limited to 'docs/guides/s3-image-upload.md') diff --git a/README.md b/README.md index 6d788ac2..7f42f862 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,11 @@ Environment variables (will overwrite other server configs) | HMD_GOOGLE_CLIENTID | no example | Google API client id | | HMD_GOOGLE_CLIENTSECRET | no example | Google API client secret | | HMD_IMGUR_CLIENTID | no example | Imgur API client id | +| HMD_IMAGE_UPLOAD_TYPE | `imgur`, `s3` or `filesystem` | Where to upload image. For S3, see our [S3 Image Upload Guide](docs/guides/s3-image-upload.md) | +| HMD_S3_ACCESS_KEY_ID | no example | AWS access key id | +| HMD_S3_SECRET_ACCESS_KEY | no example | AWS secret key | +| HMD_S3_REGION | `ap-northeast-1` | AWS S3 region | +| HMD_S3_BUCKET | no example | AWS S3 bucket name | Server settings `config.json` --- @@ -166,6 +171,8 @@ Server settings `config.json` | heartbeatinterval | `5000` | socket.io heartbeat interval | | heartbeattimeout | `10000` | socket.io heartbeat timeout | | documentmaxlength | `100000` | note max length | +| imageUploadType | `imgur`(default), `s3` or `filesystem` | Where to upload image +| s3 | `{ "accessKeyId": "YOUR_S3_ACCESS_KEY_ID", "secretAccessKey": "YOUR_S3_ACCESS_KEY", "region": "YOUR_S3_REGION", "bucket": "YOUR_S3_BUCKET_NAME" }` | When `imageUploadType` be setted to `s3`, you would also need to setup this key, check our [S3 Image Upload Guide](docs/guides/s3-image-upload.md) | Third-party integration api key settings --- diff --git a/docs/guides/s3-image-upload.md b/docs/guides/s3-image-upload.md index c92e91f8..3d6259b9 100644 --- a/docs/guides/s3-image-upload.md +++ b/docs/guides/s3-image-upload.md @@ -57,6 +57,25 @@ } ``` +8. Edit `config.json` and set following keys: + + ```javascript + { + "production": { + ... + "imageUploadType": "s3", + "s3": { + "accessKeyId": "YOUR_S3_ACCESS_KEY_ID", + "secretAccessKey": "YOUR_S3_ACCESS_KEY", + "region": "YOUR_S3_REGION", // example: ap-northeast-1 + "bucket": "YOUR_S3_BUCKET_NAME" + } + } + } + ``` + +9. In additional to edit `config.json` directly, you could also try [environment variable](https://github.com/hackmdio/hackmd#environment-variables-will-overwrite-other-server-configs). + ## Related Tools * [AWS Policy Generator](http://awspolicygen.s3.amazonaws.com/policygen.html) -- cgit v1.3.1