我们最近将 Azure Function 移至 AKS。在twistlock报告中,microsoft.data.sqlclient出现了漏洞,我们已将其升级到5.2。但在部署后,twistlock 仍报告 3.0.0 版本存在漏洞。
经过一番挖掘,我们发现它是通过 Azure Function Bundle Extensions 安装的。
有什么方法可以阻止安装这个不需要的扩展吗?
您可以利用现有的默认 Azure Function docker 映像在 AKS 中运行:-
kubectl run my-first-pod --image mcr.microsoft.com/azure-functions/dotnet:latest
kubectl expose pod myfunctionappaks --type=LoadBalancer --port=80 --name=func-aks-service
kubectl describe service func-aks-service
kubectl get svc
使用外部服务 IP 从 AKS 访问您的 Function 应用。
输出:-
您可以检查当前的
Dockerfile
并删除不需要的软件包,如下所示:-
Dockerfile:-
# Use the Azure Functions .NET base image
FROM mcr.microsoft.com/azure-functions/dotnet:latest AS base
WORKDIR /app
COPY YourFunctionApp.csproj ./
# Remove unwanted packages from the .csproj file
RUN sed -i '/<PackageReference Include="Microsoft.Data.SqlClient" Version="3.0.0" \/>/d' YourFunctionApp.csproj && \
sed -i '/<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.3" \/>/d' YourFunctionApp.csproj
RUN dotnet restore
COPY . ./
EXPOSE 80
# Define the command to run your function app when the container starts
CMD ["dotnet", "YourFunctionApp.dll"]
检查现有包是否依赖于
Microsoft.Data.SqlClient
请参阅此使用 KEDA 在 Kubernetes 上使用 Azure Functions | Microsoft Learn 使用 KEDA 在 AKS 上部署 Azure Functions。
此外,修改 Azure DevOps 或 CI/CD 管道或 Azure Functions 部署,以排除在部署时构建包。