Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix serving samples to run as non-root #5794

Closed
wants to merge 101 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
b0caa0f
fix some hello-world samples' Dockerfile to run as non-root user
prushh Dec 11, 2023
1607062
fix some cloudevents samples' Dockerfile to run as non-root user
prushh Dec 11, 2023
92854d1
fix other serving samples' Dockerfile to run as non-root user
prushh Dec 11, 2023
1086fda
Update README.md
prushh Dec 11, 2023
c95f68e
bump go to 1.21 on multi-container
prushh Dec 15, 2023
198ae74
Update README.md
prushh Dec 15, 2023
cd1ba30
fix gitwebook and secrets build errors
prushh Dec 20, 2023
2a3cc55
Bump golang.org/x/crypto from 0.14.0 to 0.17.0 (#5796)
dependabot[bot] Dec 19, 2023
e0867e5
upgrade to latest dependencies (#5797)
knative-automation Dec 19, 2023
66d6e52
Enable copy for code blocks (#5806)
ReToCode Jan 4, 2024
c12da92
Updated Copywrite Information (#5807)
professorabhay Jan 4, 2024
56aa441
improve grafana configuration steps (#5795)
prushh Jan 5, 2024
40b9aa0
Resolved the bug in the default styling of note (#5812)
professorabhay Jan 8, 2024
55ca452
Update community files (#5814)
knative-automation Jan 8, 2024
3775e98
upgrade to latest dependencies (#5816)
knative-automation Jan 9, 2024
89064b6
Update community files (#5817)
knative-automation Jan 11, 2024
94432b4
Add dynamic date on blog pages (#5801)
prushh Jan 17, 2024
e938b1a
Update community files (#5819)
knative-automation Jan 19, 2024
f2e666a
Bump h2 in /code-samples/community/serving/helloworld-rust (#5820)
dependabot[bot] Jan 22, 2024
dd04e39
Add edit Button to Documentation Pages (#5821)
YashPimple Jan 22, 2024
de82afb
Add basic doc for eventing OIDC feature (#5822)
creydr Jan 22, 2024
048b92f
Update community files (#5824)
knative-automation Jan 23, 2024
d5f97a0
Document the use of HTTP/1 full duplex support (#5818)
skonto Jan 23, 2024
593c3fe
upgrade to latest dependencies (#5827)
knative-automation Jan 24, 2024
525b451
Event types discovery - fix link to eventtype-auto-creation doc (#5828)
mgencur Jan 24, 2024
ab5d247
Add Knative v1.13.0 release blog (#5831)
Leo6Leo Jan 25, 2024
7f8542f
Update transport-encryption.md (#5825)
lysliu Jan 26, 2024
53d4a3e
fix: use links to artifact on uninstall page (#5836)
prushh Jan 29, 2024
5dda14f
Update Knative docs to 1.13 (#5837)
ReToCode Jan 29, 2024
4812731
fix http full dup example (#5839)
skonto Jan 29, 2024
b11ac6b
fix: remove sugar controller installation steps (#5834)
prushh Jan 30, 2024
b55ed8d
:lipstick: Reflect that the feature is not just for brokers, it is mo…
matzew Jan 30, 2024
a4029dc
Mention auto-create on event registry doc (#5844)
matzew Jan 30, 2024
b340930
Update the docs to reflect the changes for 1.13 operator (#5846)
houshengbo Jan 30, 2024
e7a8502
Update community files (#5848)
knative-automation Feb 1, 2024
be81741
added docs for kafka scaling to kafka source docs (#5850)
Cali0707 Feb 2, 2024
3b3e6e7
Add linux foundation trademark (#5830)
ReToCode Feb 2, 2024
f5ecb12
Document how to set Kafka Topic config options (#5854)
Cali0707 Feb 9, 2024
6d87306
Update net-istio configuration format (#5858)
pastequo Feb 12, 2024
502d063
Update community files (#5864)
knative-automation Feb 13, 2024
e3dce83
drop eventing-rabbitmq (#5861)
dprotaso Feb 13, 2024
d781806
Update community files (#5865)
knative-automation Feb 14, 2024
0d80090
Blog post about TM committee dissolving (#5852)
aliok Feb 14, 2024
5e3986b
Update community files (#5866)
knative-automation Feb 14, 2024
cbdb998
queue-sidecar annotations should be defined under spec.template.metad…
mgencur Feb 15, 2024
d64154f
Add SVA case study (#5868)
aliok Feb 15, 2024
eece1bd
Add support s390x and ppc64le archs (#5753)
lysliu Feb 16, 2024
095d8b5
Update knative-offerings.md (#5872)
igorchyts Feb 19, 2024
22a110e
Update community files (#5874)
knative-automation Feb 21, 2024
6dcc91c
upgrade to latest dependencies (#5875)
knative-automation Feb 22, 2024
0accf68
upgrade to latest dependencies (#5877)
knative-automation Feb 26, 2024
31067c4
Update community files (#5883)
knative-automation Mar 1, 2024
cff320b
Bump rack in /code-samples/serving/hello-world/helloworld-ruby (#5882)
dependabot[bot] Mar 1, 2024
cef0ee1
Improve description (#5884)
KAZYPinkSaurus Mar 3, 2024
d36e916
upgrade to latest dependencies (#5886)
knative-automation Mar 5, 2024
5276fc3
Bump mio in /code-samples/community/serving/helloworld-rust (#5892)
dependabot[bot] Mar 5, 2024
4429c5c
Implemented sliding animation for the adopter logos (#5878)
prajjwalyd Mar 5, 2024
e11af63
Bump github.com/cloudevents/sdk-go/v2 (#5893)
dependabot[bot] Mar 7, 2024
4bcaa07
Bump github.com/cloudevents/sdk-go/v2 from 2.2.0 to 2.15.2 (#5894)
dependabot[bot] Mar 7, 2024
a9b6a56
upgrade to latest dependencies (#5898)
knative-automation Mar 7, 2024
d2547d2
Sample Bookstore App: DB setup for Book Review Comments (#5896)
Zazzscoot Mar 8, 2024
06ff270
Case studies index page and link from homepage (#5869)
aliok Mar 8, 2024
2b4ccd1
Fix hard-coded version (#5902)
Kai-Z-JP Mar 11, 2024
eea823a
upgrade to latest dependencies (#5906)
knative-automation Mar 14, 2024
a387b0c
Revert "drop eventing-rabbitmq (#5861)" (#5910)
ikavgo Mar 15, 2024
1e22815
Sample App: Notification Service: camel slack sink (#5888)
Leo6Leo Mar 15, 2024
1ddf06e
Update community files (#5908)
knative-automation Mar 18, 2024
bc91a1c
Bump github.com/golang/protobuf from 1.4.3 to 1.33.0 (#5907)
dependabot[bot] Mar 19, 2024
3cc7909
Restructure eventing docs navigation (#5914)
Cali0707 Mar 20, 2024
370f1be
Blog article on "Demystifying activator on the data path" (#5709)
skonto Mar 20, 2024
d3041ae
Polish the article "Demysifying the activator on data path" (#5922)
skonto Mar 22, 2024
51248ef
Bump min-k8s version to 1.28 (#5923)
Leo6Leo Mar 25, 2024
7c5eb96
Update community files (#5924)
knative-automation Mar 27, 2024
1095678
upgrade to latest dependencies (#5925)
knative-automation Mar 27, 2024
0663df5
Bump express in /code-samples/serving/cloudevents/cloudevents-nodejs …
dependabot[bot] Mar 27, 2024
c92ce99
Bump express in /code-samples/serving/hello-world/helloworld-nodejs (…
dependabot[bot] Mar 27, 2024
d92d51b
[main] Upgrade to latest dependencies (#5929)
knative-automation Apr 2, 2024
f375f43
Knative Backstage plugin article (#5897)
aliok Apr 3, 2024
844c99d
Update community files (#5934)
knative-automation Apr 4, 2024
188d81e
Update enabling-automatic-tls-certificate-provisioning.md (#5933)
hubwoop Apr 4, 2024
0150bc7
Add documentation for Serving probes (#5855)
ReToCode Apr 5, 2024
9104c0c
Sample app frontend (#5931)
ctmphuongg Apr 5, 2024
81936c1
fix correct display (#5937)
waitstory Apr 9, 2024
30ced8d
Feat: Inappropriate language filter python script (#5935)
tico88612 Apr 9, 2024
90d5109
Sample App: Adding the db service (#5909)
Leo6Leo Apr 10, 2024
9a7eff0
Add Ceph Source to Event Sources (#5895)
zalsader Apr 11, 2024
6df0587
Add limitations for having OIDC and Istio enabled (#5940)
creydr Apr 12, 2024
9593776
Bump h2 in /code-samples/community/serving/helloworld-rust (#5936)
dependabot[bot] Apr 15, 2024
4e69af4
Update community files (#5944)
knative-automation Apr 18, 2024
b346d2c
upgrade to latest dependencies (#5942)
knative-automation Apr 18, 2024
645e0de
Bump golang.org/x/net from 0.17.0 to 0.23.0 (#5945)
dependabot[bot] Apr 22, 2024
35e4433
Add list with OIDC authn supporting eventing components (#5941)
creydr Apr 22, 2024
6766f84
upgrade to latest dependencies (#5946)
knative-automation Apr 22, 2024
5e763f0
Sample App: Event Driven Architecture I (#5928)
Leo6Leo Apr 24, 2024
e9f1f7c
Sample App: Adding the knative function build for the sentiment analy…
Leo6Leo Apr 24, 2024
f389865
Sample App: Fix the content in the bad word filter knative function c…
Leo6Leo Apr 26, 2024
5698ba7
Update community files (#5951)
knative-automation Apr 26, 2024
0495f68
Notification service docs: Add the tutorial on how to create the slac…
ctmphuongg Apr 26, 2024
a9056f0
Adding Kafka Source details on delivery spec (#5952)
matzew Apr 29, 2024
ac49fbc
Document the remaining timeout settings (#5954)
skonto Apr 30, 2024
fc606a0
Merge branch 'main' into fix-sample-images-non-root
prushh Apr 30, 2024
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
17 changes: 16 additions & 1 deletion code-samples/serving/cloudevents/cloudevents-dotnet/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ RUN dotnet publish -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-alpine
WORKDIR /app

ARG USER=appuser
ARG USER_UID=1001
ARG USER_GID=$USER_UID

# Create and change to the app directory.
WORKDIR "/home/${USER}/app"

# Add a user so the server will run as a non-root user.
RUN addgroup -g $USER_GID $USER && \
adduser -u $USER_UID -G $USER -D $USER

COPY --from=build-env /app/out .

# Set the non-root user as current.
USER $USER

ENTRYPOINT ["dotnet", "CloudEventsSample.dll"]
20 changes: 17 additions & 3 deletions code-samples/serving/cloudevents/cloudevents-go/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,24 @@ RUN go mod download
# https://hub.docker.com/_/alpine
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
FROM alpine:3
RUN apk add --no-cache ca-certificates

ARG USER=appuser
ARG USER_UID=1001
ARG USER_GID=$USER_UID

# Create and change to the app directory.
WORKDIR "/home/${USER}/app"

# Add a user so the server will run as a non-root user.
RUN addgroup -g $USER_GID $USER && \
adduser -u $USER_UID -G $USER -D $USER && \
apk add --no-cache ca-certificates

# Copy the binary to the production image from the builder stage.
COPY --from=builder /app/server /server
COPY --from=builder /app/server ./server

# Set the non-root user as current.
USER $USER

# Run the web service on container startup.
CMD ["/server"]
CMD ["./server"]
38 changes: 24 additions & 14 deletions code-samples/serving/cloudevents/cloudevents-go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ cd knative-docs/code-samples/serving/cloudevents/cloudevents-go
- [Docker](https://www.docker.com) installed and running on your local machine,
and a Docker Hub account configured (we'll use it for a container registry).

## The sample code.
## The sample code

1. If you look in `cloudevents.go`, you will see two key functions for the different modes of operation:

Expand All @@ -49,45 +49,55 @@ cd knative-docs/code-samples/serving/cloudevents/cloudevents-go

2. Choose how you would like to build the application:

### Dockerfile
### Dockerfile

- If you look in `Dockerfile`, you will see a method for pulling in the dependencies and building a small Go container based on Alpine. You can build and push this to your registry of choice via:

* If you look in `Dockerfile`, you will see a method for pulling in the dependencies and building a small Go container based on Alpine. You can build and push this to your registry of choice via:
```bash
# Build and push the container on your local machine.
docker buildx build --platform linux/arm64,linux/amd64 -t "<image>" --push .
```

### ko
### ko

- You can use [`ko`](https://github.com/google/ko) to build and push just the image with:

* You can use [`ko`](https://github.com/google/ko) to build and push just the image with:
```bash
ko publish github.com/knative/docs/code-samples/serving/cloudevents/cloudevents-go
```
However, if you use `ko` for the next step, this is not necessary.

However, if you use `ko` for the next step, this is not necessary.

3. Choose how you would like to deploy the application:

### yaml (with Dockerfile)
* If you look in `service.yaml`, take the `<image>` name you used earlier and insert it into the `image:` field, then run:
### yaml (with Dockerfile)

- If you look in `service.yaml`, take the `<image>` name you used earlier and insert it into the `image:` field, then run:

```bash
kubectl apply -f service.yaml
```

### yaml (with ko)
* If using `ko` to build and push:
### yaml (with ko)

- If using `ko` to build and push:

```bash
ko apply -f service.yaml
```

### kn (with Dockerfile)
* If using `kn` to deploy:
### kn (with Dockerfile)

- If using `kn` to deploy:

```bash
kn service create cloudevents-go --image=<IMAGE>
```

### kn (with ko)
* You can compose `kn` and `ko` to build and deploy with a single step using:
### kn (with ko)

- You can compose `kn` and `ko` to build and deploy with a single step using:

```bash
kn service create cloudevents-go --image=$(ko publish github.com/knative/docs/code-samples/serving/cloudevents/cloudevents-go)
```
Expand Down
31 changes: 23 additions & 8 deletions code-samples/serving/cloudevents/cloudevents-nodejs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,42 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM registry.access.redhat.com/ubi8/nodejs-12
FROM node:20-alpine as builder
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matzew ok with this change?


# Copy application dependency manifests to the container image.
# A wildcard is used to ensure both package.json AND package-lock.json are copied.
# Copying this separately prevents re-running npm install on every code change.
COPY package*.json ./
COPY index.js ./

# Use ci is faster and more reliable following package-lock.json
RUN npm ci --only=production

FROM node:20-alpine

ARG USER=appuser
ARG USER_UID=1001
ARG USER_GID=$USER_UID
ARG ENV=production

# Doc port listening port
ENV PORT 8080
ENV PORT=8080
ENV NODE_ENV=$ENV

EXPOSE $PORT
# Create and change to the app directory.
WORKDIR "/home/${USER}/app"

ARG ENV=production
# Add a user so the server will run as a non-root user.
RUN addgroup -g $USER_GID $USER && \
adduser -u $USER_UID -G $USER -D $USER

ENV NODE_ENV $ENV
COPY --from=builder index.js ./
COPY --from=builder package*.json ./
COPY --from=builder node_modules ./node_modules

EXPOSE $PORT

USER $USER

# Run the web service on container startup.
CMD npm run $NODE_ENV

# Copy local code to the container image.
COPY . ./
8 changes: 4 additions & 4 deletions code-samples/serving/cloudevents/cloudevents-nodejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ You can build and push this to your registry of choice via:

### yaml

To deploy the Knative service, edit the `service.yaml` file and replace `<registry/repository/image:tag>` with the image you have just created.
To deploy the Knative service, edit the `service.yaml` file and replace `<registry/repository/image:tag>` with the image you have just created.

```bash
kubectl apply -f service.yaml
```
```bash
kubectl apply -f service.yaml
```

### kn

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const receiveAndSend = (cloudEvent, res) => {
console.log(`Sent event: ${JSON.stringify(ce, null, 2)}`)
console.log(`K_SINK responded: ${JSON.stringify({ status: responseSink.status, headers: responseSink.headers, data: responseSink.data }, null, 2)}`)
})
.catch(console.error)
.catch(console.error)
}

// receiveAndReply responds with new event
Expand Down
Loading
Loading